-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [pasta_curves]: function definitions
import Aeneas
import PallasFp.Types
import PallasFp.FunsExternal
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_option linter.unusedVariables false

/- You can set the `maxHeartbeats` value with the `-max-heartbeats` CLI option -/
set_option maxHeartbeats 1000000

/- You can set the `maxRecDepth` value with the `-max-recdepth` CLI option -/
set_option maxRecDepth 2048

/- You can remove the following line by using the CLI option `-all-computable`: -/
noncomputable section

namespace pasta_curves

/-- Trait implementation: [core::array::{impl core::convert::AsRef<[T]> for [T; N]}]
    Source: '/rustc/library/core/src/array/mod.rs', lines 206:0-206:51
    Name pattern: [core::convert::AsRef<[@T; @N], [@T]>] -/
@[reducible, rust_trait_impl "core::convert::AsRef<[@T; @N], [@T]>"]
def Array.Insts.CoreConvertAsRefSlice (T : Type) (N : Std.Usize) :
  core.convert.AsRef (Array T N) (Slice T) := {
  as_ref := Array.Insts.CoreConvertAsRefSlice.as_ref
}

/-- Trait implementation: [core::array::{impl core::convert::AsMut<[T]> for [T; N]}]
    Source: '/rustc/library/core/src/array/mod.rs', lines 215:0-215:51
    Name pattern: [core::convert::AsMut<[@T; @N], [@T]>] -/
@[reducible, rust_trait_impl "core::convert::AsMut<[@T; @N], [@T]>"]
def Array.Insts.CoreConvertAsMutSlice (T : Type) (N : Std.Usize) :
  core.convert.AsMut (Array T N) (Slice T) := {
  as_mut := Array.Insts.CoreConvertAsMutSlice.as_mut
}

/-- Trait implementation: [core::array::{impl core::marker::Copy for [T; N]}]
    Source: '/rustc/library/core/src/array/mod.rs', lines 444:0-444:45
    Name pattern: [core::marker::Copy<[@T; @N]>] -/
@[reducible, rust_trait_impl "core::marker::Copy<[@T; @N]>"]
def Array.Insts.CoreMarkerCopy {T : Type} (N : Std.Usize) (markerCopyInst :
  core.marker.Copy T) : core.marker.Copy (Array T N) := {
  cloneInst := core.clone.CloneArray N markerCopyInst.cloneInst
}

/-- Trait implementation: [core::borrow::{impl core::borrow::Borrow<T> for T}]
    Source: '/rustc/library/core/src/borrow.rs', lines 212:0-212:37
    Name pattern: [core::borrow::Borrow<@T, @T>] -/
@[reducible, rust_trait_impl "core::borrow::Borrow<@T, @T>"]
def core.borrow.Borrow.Blanket (T : Type) : core.borrow.Borrow T T := {
  borrow := core.borrow.Borrow.Blanket.borrow
}

/-- Trait implementation: [core::borrow::{impl core::borrow::Borrow<T> for &'_0 T}]
    Source: '/rustc/library/core/src/borrow.rs', lines 229:0-229:38
    Name pattern: [core::borrow::Borrow<&'0 @T, @T>] -/
@[reducible, rust_trait_impl "core::borrow::Borrow<&'0 @T, @T>"]
def Shared0T.Insts.CoreBorrowBorrow (T : Type) : core.borrow.Borrow T T := {
  borrow := Shared0T.Insts.CoreBorrowBorrow.borrow
}

/-- Trait implementation: [core::convert::{impl core::convert::AsRef<U> for &'_0 T}]
    Source: '/rustc/library/core/src/convert/mod.rs', lines 712:0-714:24
    Name pattern: [core::convert::AsRef<&'0 @T, @U>] -/
@[reducible, rust_trait_impl "core::convert::AsRef<&'0 @T, @U>"]
def Shared0T.Insts.CoreConvertAsRef {T : Type} {U : Type} (AsRefInst :
  core.convert.AsRef T U) : core.convert.AsRef T U := {
  as_ref := Shared0T.Insts.CoreConvertAsRef.as_ref AsRefInst
}

/-- [pasta_curves::arithmetic::fields::adc]:
    Source: 'src/arithmetic/fields.rs', lines 241:0-244:1 -/
def arithmetic.fields.adc
  (a : Std.U64) (b : Std.U64) (carry : Std.U64) :
  Result (Std.U64 × Std.U64)
  := do
  let i ← lift (UScalar.cast .U128 a)
  let i1 ← lift (UScalar.cast .U128 b)
  let i2 ← i + i1
  let i3 ← lift (UScalar.cast .U128 carry)
  let ret ← i2 + i3
  let i4 ← lift (UScalar.cast .U64 ret)
  let i5 ← ret >>> 64#i32
  let i6 ← lift (UScalar.cast .U64 i5)
  ok (i4, i6)

/-- [pasta_curves::arithmetic::fields::sbb]:
    Source: 'src/arithmetic/fields.rs', lines 248:0-251:1 -/
def arithmetic.fields.sbb
  (a : Std.U64) (b : Std.U64) (borrow : Std.U64) :
  Result (Std.U64 × Std.U64)
  := do
  let i ← lift (UScalar.cast .U128 a)
  let i1 ← lift (UScalar.cast .U128 b)
  let i2 ← borrow >>> 63#i32
  let i3 ← lift (UScalar.cast .U128 i2)
  let i4 ← i1 + i3
  let ret ← lift (core.num.U128.wrapping_sub i i4)
  let i5 ← lift (UScalar.cast .U64 ret)
  let i6 ← ret >>> 64#i32
  let i7 ← lift (UScalar.cast .U64 i6)
  ok (i5, i7)

/-- [pasta_curves::arithmetic::fields::mac]:
    Source: 'src/arithmetic/fields.rs', lines 255:0-258:1 -/
def arithmetic.fields.mac
  (a : Std.U64) (b : Std.U64) (c : Std.U64) (carry : Std.U64) :
  Result (Std.U64 × Std.U64)
  := do
  let i ← lift (UScalar.cast .U128 a)
  let i1 ← lift (UScalar.cast .U128 b)
  let i2 ← lift (UScalar.cast .U128 c)
  let i3 ← i1 * i2
  let i4 ← i + i3
  let i5 ← lift (UScalar.cast .U128 carry)
  let ret ← i4 + i5
  let i6 ← lift (UScalar.cast .U64 ret)
  let i7 ← ret >>> 64#i32
  let i8 ← lift (UScalar.cast .U64 i7)
  ok (i6, i8)

/-- [pasta_curves::fields::fp::{impl core::clone::Clone for pasta_curves::fields::fp::Fp}::clone]:
    Source: 'src/fields/fp.rs', lines 29:9-29:14
    Visibility: public -/
def fields.fp.Fp.Insts.CoreCloneClone.clone
  (self : fields.fp.Fp) : Result fields.fp.Fp := do
  ok self

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::clone::Clone for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 29:9-29:14 -/
@[reducible]
def fields.fp.Fp.Insts.CoreCloneClone : core.clone.Clone fields.fp.Fp := {
  clone := fields.fp.Fp.Insts.CoreCloneClone.clone
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::marker::Copy for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 29:16-29:20 -/
@[reducible]
def fields.fp.Fp.Insts.CoreMarkerCopy : core.marker.Copy fields.fp.Fp := {
  cloneInst := fields.fp.Fp.Insts.CoreCloneClone
}

/-- [pasta_curves::fields::fp::{impl subtle::ConstantTimeEq for pasta_curves::fields::fp::Fp}::ct_eq]:
    Source: 'src/fields/fp.rs', lines 61:4-66:5
    Visibility: public -/
def fields.fp.Fp.Insts.SubtleConstantTimeEq.ct_eq
  (self : fields.fp.Fp) (other : fields.fp.Fp) : Result subtle.Choice := do
  let i ← Array.index_usize self 0#usize
  let i1 ← Array.index_usize other 0#usize
  let c ← U64.Insts.SubtleConstantTimeEq.ct_eq i i1
  let i2 ← Array.index_usize self 1#usize
  let i3 ← Array.index_usize other 1#usize
  let c1 ← U64.Insts.SubtleConstantTimeEq.ct_eq i2 i3
  let c2 ← subtle.Choice.Insts.CoreOpsBitBitAndChoiceChoice.bitand c c1
  let i4 ← Array.index_usize self 2#usize
  let i5 ← Array.index_usize other 2#usize
  let c3 ← U64.Insts.SubtleConstantTimeEq.ct_eq i4 i5
  let c4 ← subtle.Choice.Insts.CoreOpsBitBitAndChoiceChoice.bitand c2 c3
  let i6 ← Array.index_usize self 3#usize
  let i7 ← Array.index_usize other 3#usize
  let c5 ← U64.Insts.SubtleConstantTimeEq.ct_eq i6 i7
  subtle.Choice.Insts.CoreOpsBitBitAndChoiceChoice.bitand c4 c5

/-- [pasta_curves::fields::fp::{impl core::cmp::PartialEq<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::eq]:
    Source: 'src/fields/fp.rs', lines 71:4-73:5
    Visibility: public -/
def fields.fp.Fp.Insts.CoreCmpPartialEqFp.eq
  (self : fields.fp.Fp) (other : fields.fp.Fp) : Result Bool := do
  let c ← fields.fp.Fp.Insts.SubtleConstantTimeEq.ct_eq self other
  let i ← subtle.Choice.unwrap_u8 c
  ok (i = 1#u8)

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::cmp::PartialEq<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 69:0-74:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreCmpPartialEqFp : core.cmp.PartialEq fields.fp.Fp
  fields.fp.Fp := {
  eq := fields.fp.Fp.Insts.CoreCmpPartialEqFp.eq
}

/-- [pasta_curves::fields::fp::{impl core::cmp::Eq for pasta_curves::fields::fp::Fp}::assert_fields_are_eq]:
    Source: 'src/fields/fp.rs', lines 29:22-29:24
    Visibility: public -/
def fields.fp.Fp.Insts.CoreCmpEq.assert_fields_are_eq
  (self : fields.fp.Fp) : Result Unit := do
  ok ()

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::cmp::Eq for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 29:22-29:24 -/
@[reducible]
def fields.fp.Fp.Insts.CoreCmpEq : core.cmp.Eq fields.fp.Fp := {
  partialEqInst := fields.fp.Fp.Insts.CoreCmpPartialEqFp
  assert_fields_are_eq := fields.fp.Fp.Insts.CoreCmpEq.assert_fields_are_eq
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::fmt::Debug for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 33:0-42:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreFmtDebug : core.fmt.Debug fields.fp.Fp := {
  fmt := fields.fp.Fp.Insts.CoreFmtDebug.fmt
}

/-- [pasta_curves::fields::fp::R]
    Source: 'src/fields/fp.rs', lines 194:0-199:3 -/
@[global_simps, irreducible]
def fields.fp.R : fields.fp.Fp :=
  Array.make 4#usize [
    3780891978758094845#u64, 11037255111966004397#u64,
    18446744073709551615#u64, 4611686018427387903#u64
    ]

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::one]:
    Source: 'src/fields/fp.rs', lines 273:4-275:5
    Visibility: public -/
def fields.fp.Fp.one : Result fields.fp.Fp := do
  ok fields.fp.R

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::zero]:
    Source: 'src/fields/fp.rs', lines 267:4-269:5
    Visibility: public -/
def fields.fp.Fp.zero : Result fields.fp.Fp := do
  let a := Array.repeat 4#usize 0#u64
  ok a

/-- [pasta_curves::fields::fp::{impl core::convert::From<bool> for pasta_curves::fields::fp::Fp}::from]:
    Source: 'src/fields/fp.rs', lines 45:4-51:5
    Visibility: public -/
def fields.fp.Fp.Insts.CoreConvertFromBool.from
  (bit : Bool) : Result fields.fp.Fp := do
  if bit
  then fields.fp.Fp.one
  else fields.fp.Fp.zero

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::convert::From<bool> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 44:0-52:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreConvertFromBool : core.convert.From fields.fp.Fp
  Bool := {
  from_ := fields.fp.Fp.Insts.CoreConvertFromBool.from
}

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::mul_unreduced]:
    Source: 'src/fields/fp.rs', lines 423:4-447:5 -/
def fields.fp.Fp.mul_unreduced
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) :
  Result (Array Std.U64 8#usize)
  := do
  let i ← Array.index_usize self 0#usize
  let i1 ← Array.index_usize rhs 0#usize
  let (r0, carry) ← arithmetic.fields.mac 0#u64 i i1 0#u64
  let i2 ← Array.index_usize rhs 1#usize
  let (r1, carry1) ← arithmetic.fields.mac 0#u64 i i2 carry
  let i3 ← Array.index_usize rhs 2#usize
  let (r2, carry2) ← arithmetic.fields.mac 0#u64 i i3 carry1
  let i4 ← Array.index_usize rhs 3#usize
  let (r3, r4) ← arithmetic.fields.mac 0#u64 i i4 carry2
  let i5 ← Array.index_usize self 1#usize
  let (r11, carry3) ← arithmetic.fields.mac r1 i5 i1 0#u64
  let (r21, carry4) ← arithmetic.fields.mac r2 i5 i2 carry3
  let (r31, carry5) ← arithmetic.fields.mac r3 i5 i3 carry4
  let (r41, r5) ← arithmetic.fields.mac r4 i5 i4 carry5
  let i6 ← Array.index_usize self 2#usize
  let (r22, carry6) ← arithmetic.fields.mac r21 i6 i1 0#u64
  let (r32, carry7) ← arithmetic.fields.mac r31 i6 i2 carry6
  let (r42, carry8) ← arithmetic.fields.mac r41 i6 i3 carry7
  let (r51, r6) ← arithmetic.fields.mac r5 i6 i4 carry8
  let i7 ← Array.index_usize self 3#usize
  let (r33, carry9) ← arithmetic.fields.mac r32 i7 i1 0#u64
  let (r43, carry10) ← arithmetic.fields.mac r42 i7 i2 carry9
  let (r52, carry11) ← arithmetic.fields.mac r51 i7 i3 carry10
  let (r61, r7) ← arithmetic.fields.mac r6 i7 i4 carry11
  ok (Array.make 8#usize [ r0, r11, r22, r33, r43, r52, r61, r7 ])

/-- [pasta_curves::fields::fp::MODULUS]
    Source: 'src/fields/fp.rs', lines 110:0-115:3 -/
@[global_simps, irreducible]
def fields.fp.MODULUS : fields.fp.Fp :=
  Array.make 4#usize [
    11037532056220336129#u64, 2469829653914515739#u64, 0#u64,
    4611686018427387904#u64
    ]

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::sub]:
    Source: 'src/fields/fp.rs', lines 374:4-388:5
    Visibility: public -/
def fields.fp.Fp.sub
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  let i ← Array.index_usize self 0#usize
  let i1 ← Array.index_usize rhs 0#usize
  let (d0, borrow) ← arithmetic.fields.sbb i i1 0#u64
  let i2 ← Array.index_usize self 1#usize
  let i3 ← Array.index_usize rhs 1#usize
  let (d1, borrow1) ← arithmetic.fields.sbb i2 i3 borrow
  let i4 ← Array.index_usize self 2#usize
  let i5 ← Array.index_usize rhs 2#usize
  let (d2, borrow2) ← arithmetic.fields.sbb i4 i5 borrow1
  let i6 ← Array.index_usize self 3#usize
  let i7 ← Array.index_usize rhs 3#usize
  let (d3, borrow3) ← arithmetic.fields.sbb i6 i7 borrow2
  let a := fields.fp.MODULUS
  let i8 ← Array.index_usize a 0#usize
  let i9 ← lift (i8 &&& borrow3)
  let (d01, carry) ← arithmetic.fields.adc d0 i9 0#u64
  let a1 := fields.fp.MODULUS
  let i10 ← Array.index_usize a1 1#usize
  let i11 ← lift (i10 &&& borrow3)
  let (d11, carry1) ← arithmetic.fields.adc d1 i11 carry
  let a2 := fields.fp.MODULUS
  let i12 ← Array.index_usize a2 2#usize
  let i13 ← lift (i12 &&& borrow3)
  let (d21, carry2) ← arithmetic.fields.adc d2 i13 carry1
  let a3 := fields.fp.MODULUS
  let i14 ← Array.index_usize a3 3#usize
  let i15 ← lift (i14 &&& borrow3)
  let (d31, _) ← arithmetic.fields.adc d3 i15 carry2
  ok (Array.make 4#usize [ d01, d11, d21, d31 ])

/-- [pasta_curves::fields::fp::INV]
    Source: 'src/fields/fp.rs', lines 191:0-191:36 -/
@[global_simps, irreducible]
def fields.fp.INV : Std.U64 := 11037532056220336127#u64

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::montgomery_reduce]:
    Source: 'src/fields/fp.rs', lines 319:4-363:5 -/
def fields.fp.Fp.montgomery_reduce
  (r0 : Std.U64) (r1 : Std.U64) (r2 : Std.U64) (r3 : Std.U64) (r4 : Std.U64)
  (r5 : Std.U64) (r6 : Std.U64) (r7 : Std.U64) :
  Result fields.fp.Fp
  := do
  let k ← lift (core.num.U64.wrapping_mul r0 fields.fp.INV)
  let a := fields.fp.MODULUS
  let i ← Array.index_usize a 0#usize
  let (_, carry) ← arithmetic.fields.mac r0 k i 0#u64
  let a1 := fields.fp.MODULUS
  let i1 ← Array.index_usize a1 1#usize
  let (r11, carry1) ← arithmetic.fields.mac r1 k i1 carry
  let a2 := fields.fp.MODULUS
  let i2 ← Array.index_usize a2 2#usize
  let (r21, carry2) ← arithmetic.fields.mac r2 k i2 carry1
  let a3 := fields.fp.MODULUS
  let i3 ← Array.index_usize a3 3#usize
  let (r31, carry3) ← arithmetic.fields.mac r3 k i3 carry2
  let (r41, carry21) ← arithmetic.fields.adc r4 0#u64 carry3
  let k1 ← lift (core.num.U64.wrapping_mul r11 fields.fp.INV)
  let a4 := fields.fp.MODULUS
  let i4 ← Array.index_usize a4 0#usize
  let (_, carry4) ← arithmetic.fields.mac r11 k1 i4 0#u64
  let a5 := fields.fp.MODULUS
  let i5 ← Array.index_usize a5 1#usize
  let (r22, carry5) ← arithmetic.fields.mac r21 k1 i5 carry4
  let a6 := fields.fp.MODULUS
  let i6 ← Array.index_usize a6 2#usize
  let (r32, carry6) ← arithmetic.fields.mac r31 k1 i6 carry5
  let a7 := fields.fp.MODULUS
  let i7 ← Array.index_usize a7 3#usize
  let (r42, carry7) ← arithmetic.fields.mac r41 k1 i7 carry6
  let (r51, carry22) ← arithmetic.fields.adc r5 carry21 carry7
  let k2 ← lift (core.num.U64.wrapping_mul r22 fields.fp.INV)
  let a8 := fields.fp.MODULUS
  let i8 ← Array.index_usize a8 0#usize
  let (_, carry8) ← arithmetic.fields.mac r22 k2 i8 0#u64
  let a9 := fields.fp.MODULUS
  let i9 ← Array.index_usize a9 1#usize
  let (r33, carry9) ← arithmetic.fields.mac r32 k2 i9 carry8
  let a10 := fields.fp.MODULUS
  let i10 ← Array.index_usize a10 2#usize
  let (r43, carry10) ← arithmetic.fields.mac r42 k2 i10 carry9
  let a11 := fields.fp.MODULUS
  let i11 ← Array.index_usize a11 3#usize
  let (r52, carry11) ← arithmetic.fields.mac r51 k2 i11 carry10
  let (r61, carry23) ← arithmetic.fields.adc r6 carry22 carry11
  let k3 ← lift (core.num.U64.wrapping_mul r33 fields.fp.INV)
  let a12 := fields.fp.MODULUS
  let i12 ← Array.index_usize a12 0#usize
  let (_, carry12) ← arithmetic.fields.mac r33 k3 i12 0#u64
  let a13 := fields.fp.MODULUS
  let i13 ← Array.index_usize a13 1#usize
  let (r44, carry13) ← arithmetic.fields.mac r43 k3 i13 carry12
  let a14 := fields.fp.MODULUS
  let i14 ← Array.index_usize a14 2#usize
  let (r53, carry14) ← arithmetic.fields.mac r52 k3 i14 carry13
  let a15 := fields.fp.MODULUS
  let i15 ← Array.index_usize a15 3#usize
  let (r62, carry15) ← arithmetic.fields.mac r61 k3 i15 carry14
  let (r71, _) ← arithmetic.fields.adc r7 carry23 carry15
  fields.fp.Fp.sub (Array.make 4#usize [ r44, r53, r62, r71 ])
    fields.fp.MODULUS

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::mul]:
    Source: 'src/fields/fp.rs', lines 367:4-370:5
    Visibility: public -/
def fields.fp.Fp.mul
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  let u ← fields.fp.Fp.mul_unreduced self rhs
  let i ← Array.index_usize u 0#usize
  let i1 ← Array.index_usize u 1#usize
  let i2 ← Array.index_usize u 2#usize
  let i3 ← Array.index_usize u 3#usize
  let i4 ← Array.index_usize u 4#usize
  let i5 ← Array.index_usize u 5#usize
  let i6 ← Array.index_usize u 6#usize
  let i7 ← Array.index_usize u 7#usize
  fields.fp.Fp.montgomery_reduce i i1 i2 i3 i4 i5 i6 i7

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Mul<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::mul]:
    Source: 'src/fields/fp.rs', lines 170:4-172:5
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.mul self rhs

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Mul<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::mul]:
    Source: 'src/macros.rs', lines 94:12-96:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithMulFpFp.mul
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul self rhs

/-- [pasta_curves::fields::fp::R2]
    Source: 'src/fields/fp.rs', lines 202:0-207:3 -/
@[global_simps, irreducible]
def fields.fp.R2 : fields.fp.Fp :=
  Array.make 4#usize [
    10122100416058490895#u64, 15551789045973377255#u64,
    8617542898466512152#u64, 679271340751763220#u64
    ]

/-- [pasta_curves::fields::fp::{impl core::convert::From<u64> for pasta_curves::fields::fp::Fp}::from]:
    Source: 'src/fields/fp.rs', lines 55:4-57:5
    Visibility: public -/
def fields.fp.Fp.Insts.CoreConvertFromU64.from
  (val : Std.U64) : Result fields.fp.Fp := do
  fields.fp.Fp.Insts.CoreOpsArithMulFpFp.mul
    (Array.make 4#usize [ val, 0#u64, 0#u64, 0#u64 ]) fields.fp.R2

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::convert::From<u64> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 54:0-58:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreConvertFromU64 : core.convert.From fields.fp.Fp
  Std.U64 := {
  from_ := fields.fp.Fp.Insts.CoreConvertFromU64.from
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl subtle::ConstantTimeEq for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 60:0-67:1 -/
@[reducible]
def fields.fp.Fp.Insts.SubtleConstantTimeEq : subtle.ConstantTimeEq
  fields.fp.Fp := {
  ct_eq := fields.fp.Fp.Insts.SubtleConstantTimeEq.ct_eq
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::cmp::PartialOrd<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 91:0-95:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreCmpPartialOrdFp : core.cmp.PartialOrd fields.fp.Fp
  fields.fp.Fp := {
  partialEqInst := fields.fp.Fp.Insts.CoreCmpPartialEqFp
  partial_cmp := fields.fp.Fp.Insts.CoreCmpPartialOrdFp.partial_cmp
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::cmp::Ord for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 76:0-89:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreCmpOrd : core.cmp.Ord fields.fp.Fp := {
  eqInst := fields.fp.Fp.Insts.CoreCmpEq
  partialOrdInst := fields.fp.Fp.Insts.CoreCmpPartialOrdFp
  cmp := fields.fp.Fp.Insts.CoreCmpOrd.cmp
}

/-- [pasta_curves::fields::fp::{impl subtle::ConditionallySelectable for pasta_curves::fields::fp::Fp}::conditional_select]:
    Source: 'src/fields/fp.rs', lines 98:4-105:5
    Visibility: public -/
def fields.fp.Fp.Insts.SubtleConditionallySelectable.conditional_select
  (a : fields.fp.Fp) (b : fields.fp.Fp) (choice : subtle.Choice) :
  Result fields.fp.Fp
  := do
  let i ← Array.index_usize a 0#usize
  let i1 ← Array.index_usize b 0#usize
  let i2 ←
    U64.Insts.SubtleConditionallySelectable.conditional_select i i1 choice
  let i3 ← Array.index_usize a 1#usize
  let i4 ← Array.index_usize b 1#usize
  let i5 ←
    U64.Insts.SubtleConditionallySelectable.conditional_select i3 i4 choice
  let i6 ← Array.index_usize a 2#usize
  let i7 ← Array.index_usize b 2#usize
  let i8 ←
    U64.Insts.SubtleConditionallySelectable.conditional_select i6 i7 choice
  let i9 ← Array.index_usize a 3#usize
  let i10 ← Array.index_usize b 3#usize
  let i11 ←
    U64.Insts.SubtleConditionallySelectable.conditional_select i9 i10 choice
  ok (Array.make 4#usize [ i2, i5, i8, i11 ])

/-- Trait implementation: [pasta_curves::fields::fp::{impl subtle::ConditionallySelectable for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 97:0-106:1 -/
@[reducible]
def fields.fp.Fp.Insts.SubtleConditionallySelectable :
  subtle.ConditionallySelectable fields.fp.Fp := {
  coremarkerCopyInst := fields.fp.Fp.Insts.CoreMarkerCopy
  conditional_select :=
    fields.fp.Fp.Insts.SubtleConditionallySelectable.conditional_select
}

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::neg]:
    Source: 'src/fields/fp.rs', lines 405:4-419:5
    Visibility: public -/
def fields.fp.Fp.neg (self : fields.fp.Fp) : Result fields.fp.Fp := do
  let a := fields.fp.MODULUS
  let i ← Array.index_usize a 0#usize
  let i1 ← Array.index_usize self 0#usize
  let (d0, borrow) ← arithmetic.fields.sbb i i1 0#u64
  let a1 := fields.fp.MODULUS
  let i2 ← Array.index_usize a1 1#usize
  let i3 ← Array.index_usize self 1#usize
  let (d1, borrow1) ← arithmetic.fields.sbb i2 i3 borrow
  let a2 := fields.fp.MODULUS
  let i4 ← Array.index_usize a2 2#usize
  let i5 ← Array.index_usize self 2#usize
  let (d2, borrow2) ← arithmetic.fields.sbb i4 i5 borrow1
  let a3 := fields.fp.MODULUS
  let i6 ← Array.index_usize a3 3#usize
  let i7 ← Array.index_usize self 3#usize
  let (d3, _) ← arithmetic.fields.sbb i6 i7 borrow2
  let i8 ← lift (i1 ||| i3)
  let i9 ← lift (i8 ||| i5)
  let i10 ← lift (i9 ||| i7)
  let i11 ← lift (UScalar.cast_fromBool .U64 (i10 = 0#u64))
  let mask ← lift (core.num.U64.wrapping_sub i11 1#u64)
  let i12 ← lift (d0 &&& mask)
  let i13 ← lift (d1 &&& mask)
  let i14 ← lift (d2 &&& mask)
  let i15 ← lift (d3 &&& mask)
  ok (Array.make 4#usize [ i12, i13, i14, i15 ])

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Neg<pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::neg]:
    Source: 'src/fields/fp.rs', lines 134:4-136:5
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithNegFp.neg
  (self : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.neg self

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Neg<pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 130:0-137:1 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithNegFp : core.ops.arith.Neg fields.fp.Fp
  fields.fp.Fp := {
  neg := SharedAFp.Insts.CoreOpsArithNegFp.neg
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Neg<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::neg]:
    Source: 'src/fields/fp.rs', lines 143:4-145:5
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithNegFp.neg
  (self : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithNegFp.neg self

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Neg<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 139:0-146:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithNegFp : core.ops.arith.Neg fields.fp.Fp
  fields.fp.Fp := {
  neg := fields.fp.Fp.Insts.CoreOpsArithNegFp.neg
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Sub<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::sub]:
    Source: 'src/fields/fp.rs', lines 152:4-154:5
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.sub self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Sub<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 148:0-155:1 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithSubSharedBFpFp : core.ops.arith.Sub
  fields.fp.Fp fields.fp.Fp fields.fp.Fp := {
  sub := SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub
}

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::add]:
    Source: 'src/fields/fp.rs', lines 392:4-401:5
    Visibility: public -/
def fields.fp.Fp.add
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  let i ← Array.index_usize self 0#usize
  let i1 ← Array.index_usize rhs 0#usize
  let (d0, carry) ← arithmetic.fields.adc i i1 0#u64
  let i2 ← Array.index_usize self 1#usize
  let i3 ← Array.index_usize rhs 1#usize
  let (d1, carry1) ← arithmetic.fields.adc i2 i3 carry
  let i4 ← Array.index_usize self 2#usize
  let i5 ← Array.index_usize rhs 2#usize
  let (d2, carry2) ← arithmetic.fields.adc i4 i5 carry1
  let i6 ← Array.index_usize self 3#usize
  let i7 ← Array.index_usize rhs 3#usize
  let (d3, _) ← arithmetic.fields.adc i6 i7 carry2
  fields.fp.Fp.sub (Array.make 4#usize [ d0, d1, d2, d3 ]) fields.fp.MODULUS

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Add<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::add]:
    Source: 'src/fields/fp.rs', lines 161:4-163:5
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.add self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Add<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 157:0-164:1 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithAddSharedBFpFp : core.ops.arith.Add
  fields.fp.Fp fields.fp.Fp fields.fp.Fp := {
  add := SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Mul<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 166:0-173:1 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithMulSharedBFpFp : core.ops.arith.Mul
  fields.fp.Fp fields.fp.Fp fields.fp.Fp := {
  mul := SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::iter::traits::accum::Sum<T> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 178:0-182:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreIterTraitsAccumSum {T : Type}
  (coreborrowBorrowTFpInst : core.borrow.Borrow T fields.fp.Fp) :
  core.iter.traits.accum.Sum fields.fp.Fp T := {
  sum := fun {I : Type} (coreitertraitsiteratorIteratorInst :
    core.iter.traits.iterator.Iterator I T) =>
    fields.fp.Fp.Insts.CoreIterTraitsAccumSum.sum coreborrowBorrowTFpInst
    coreitertraitsiteratorIteratorInst
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::iter::traits::accum::Product<T> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 184:0-188:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreIterTraitsAccumProduct {T : Type}
  (coreborrowBorrowTFpInst : core.borrow.Borrow T fields.fp.Fp) :
  core.iter.traits.accum.Product fields.fp.Fp T := {
  product := fun {I : Type} (coreitertraitsiteratorIteratorInst :
    core.iter.traits.iterator.Iterator I T) =>
    fields.fp.Fp.Insts.CoreIterTraitsAccumProduct.product
    coreborrowBorrowTFpInst coreitertraitsiteratorIteratorInst
}

/-- [pasta_curves::fields::fp::R3]
    Source: 'src/fields/fp.rs', lines 210:0-215:3 -/
@[global_simps, irreducible]
def fields.fp.R3 : fields.fp.Fp :=
  Array.make 4#usize [
    17403498412575166713#u64, 17773050464821424593#u64,
    16108549121152898092#u64, 3090323811697793296#u64
    ]

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::from_raw]:
    Source: 'src/fields/fp.rs', lines 306:4-308:5
    Visibility: public -/
def fields.fp.Fp.from_raw
  (val : Array Std.U64 4#usize) : Result fields.fp.Fp := do
  fields.fp.Fp.mul val fields.fp.R2

/-- [pasta_curves::fields::fp::GENERATOR]
    Source: 'src/fields/fp.rs', lines 219:0-224:3 -/
@[global_simps, irreducible]
def fields.fp.GENERATOR : Result fields.fp.Fp :=
  fields.fp.Fp.from_raw (Array.make 4#usize [ 5#u64, 0#u64, 0#u64, 0#u64 ])

/-- [pasta_curves::fields::fp::S]
    Source: 'src/fields/fp.rs', lines 226:0-226:18 -/
@[global_simps, irreducible] def fields.fp.S : Std.U32 := 32#u32

/-- [pasta_curves::fields::fp::ROOT_OF_UNITY]
    Source: 'src/fields/fp.rs', lines 231:0-236:3 -/
@[global_simps, irreducible]
def fields.fp.ROOT_OF_UNITY : Result fields.fp.Fp :=
  fields.fp.Fp.from_raw
    (Array.make 4#usize [
      13667703228001592111#u64, 16875599075175265668#u64,
      3900434499382671386#u64, 3156588888553745370#u64
      ])

/-- [pasta_curves::fields::fp::DELTA]
    Source: 'src/fields/fp.rs', lines 241:0-246:3 -/
@[global_simps, irreducible]
def fields.fp.DELTA : Result fields.fp.Fp :=
  fields.fp.Fp.from_raw
    (Array.make 4#usize [
      7668729806543625122#u64, 17718555051450848822#u64,
      13638407587763651741#u64, 753646016032844652#u64
      ])

/-- [pasta_curves::fields::fp::T_MINUS1_OVER2]
    Source: 'src/fields/fp.rs', lines 250:0-255:2 -/
@[global_simps, irreducible]
def fields.fp.T_MINUS1_OVER2 : Array Std.U64 4#usize :=
  Array.make 4#usize [
    335092170750335094#u64, 287526014#u64, 0#u64, 536870912#u64
    ]

/-- [pasta_curves::fields::fp::{impl core::default::Default for pasta_curves::fields::fp::Fp}::default]:
    Source: 'src/fields/fp.rs', lines 259:4-261:5
    Visibility: public -/
def fields.fp.Fp.Insts.CoreDefaultDefault.default : Result fields.fp.Fp := do
  fields.fp.Fp.zero

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::default::Default for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 257:0-262:1 -/
@[reducible]
def fields.fp.Fp.Insts.CoreDefaultDefault : core.default.Default fields.fp.Fp
  := {
  default := fields.fp.Fp.Insts.CoreDefaultDefault.default
}

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::double]:
    Source: 'src/fields/fp.rs', lines 279:4-282:5
    Visibility: public -/
def fields.fp.Fp.double (self : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.add self self

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Add<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::add]:
    Source: 'src/macros.rs', lines 25:12-27:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithAddFpFp.add
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add self rhs

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::from_u512]:
    Source: 'src/fields/fp.rs', lines 284:4-302:5 -/
def fields.fp.Fp.from_u512
  (limbs : Array Std.U64 8#usize) : Result fields.fp.Fp := do
  let i ← Array.index_usize limbs 0#usize
  let i1 ← Array.index_usize limbs 1#usize
  let i2 ← Array.index_usize limbs 2#usize
  let i3 ← Array.index_usize limbs 3#usize
  let i4 ← Array.index_usize limbs 4#usize
  let i5 ← Array.index_usize limbs 5#usize
  let i6 ← Array.index_usize limbs 6#usize
  let i7 ← Array.index_usize limbs 7#usize
  let f ←
    fields.fp.Fp.Insts.CoreOpsArithMulFpFp.mul
      (Array.make 4#usize [ i, i1, i2, i3 ]) fields.fp.R2
  let f1 ←
    fields.fp.Fp.Insts.CoreOpsArithMulFpFp.mul
      (Array.make 4#usize [ i4, i5, i6, i7 ]) fields.fp.R3
  fields.fp.Fp.Insts.CoreOpsArithAddFpFp.add f f1

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::square_unreduced]:
    Source: 'src/fields/fp.rs', lines 451:4-479:5 -/
def fields.fp.Fp.square_unreduced
  (self : fields.fp.Fp) : Result (Array Std.U64 8#usize) := do
  let i ← Array.index_usize self 0#usize
  let i1 ← Array.index_usize self 1#usize
  let (r1, carry) ← arithmetic.fields.mac 0#u64 i i1 0#u64
  let i2 ← Array.index_usize self 2#usize
  let (r2, carry1) ← arithmetic.fields.mac 0#u64 i i2 carry
  let i3 ← Array.index_usize self 3#usize
  let (r3, r4) ← arithmetic.fields.mac 0#u64 i i3 carry1
  let (r31, carry2) ← arithmetic.fields.mac r3 i1 i2 0#u64
  let (r41, r5) ← arithmetic.fields.mac r4 i1 i3 carry2
  let (r51, r6) ← arithmetic.fields.mac r5 i2 i3 0#u64
  let r7 ← r6 >>> 63#i32
  let i4 ← r6 <<< 1#i32
  let i5 ← r51 >>> 63#i32
  let r61 ← lift (i4 ||| i5)
  let i6 ← r51 <<< 1#i32
  let i7 ← r41 >>> 63#i32
  let r52 ← lift (i6 ||| i7)
  let i8 ← r41 <<< 1#i32
  let i9 ← r31 >>> 63#i32
  let r42 ← lift (i8 ||| i9)
  let i10 ← r31 <<< 1#i32
  let i11 ← r2 >>> 63#i32
  let r32 ← lift (i10 ||| i11)
  let i12 ← r2 <<< 1#i32
  let i13 ← r1 >>> 63#i32
  let r21 ← lift (i12 ||| i13)
  let r11 ← r1 <<< 1#i32
  let (r0, carry3) ← arithmetic.fields.mac 0#u64 i i 0#u64
  let (r12, carry4) ← arithmetic.fields.adc 0#u64 r11 carry3
  let (r22, carry5) ← arithmetic.fields.mac r21 i1 i1 carry4
  let (r33, carry6) ← arithmetic.fields.adc 0#u64 r32 carry5
  let (r43, carry7) ← arithmetic.fields.mac r42 i2 i2 carry6
  let (r53, carry8) ← arithmetic.fields.adc 0#u64 r52 carry7
  let (r62, carry9) ← arithmetic.fields.mac r61 i3 i3 carry8
  let (r71, _) ← arithmetic.fields.adc 0#u64 r7 carry9
  ok (Array.make 8#usize [ r0, r12, r22, r33, r43, r53, r62, r71 ])

/-- [pasta_curves::fields::fp::{pasta_curves::fields::fp::Fp}::square]:
    Source: 'src/fields/fp.rs', lines 312:4-315:5
    Visibility: public -/
def fields.fp.Fp.square (self : fields.fp.Fp) : Result fields.fp.Fp := do
  let u ← fields.fp.Fp.square_unreduced self
  let i ← Array.index_usize u 0#usize
  let i1 ← Array.index_usize u 1#usize
  let i2 ← Array.index_usize u 2#usize
  let i3 ← Array.index_usize u 3#usize
  let i4 ← Array.index_usize u 4#usize
  let i5 ← Array.index_usize u 5#usize
  let i6 ← Array.index_usize u 6#usize
  let i7 ← Array.index_usize u 7#usize
  fields.fp.Fp.montgomery_reduce i i1 i2 i3 i4 i5 i6 i7

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::to_repr]:
    Source: 'src/fields/fp.rs', lines 674:4-686:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.to_repr
  (self : fields.fp.Fp) : Result (Array Std.U8 32#usize) := do
  let i ← Array.index_usize self 0#usize
  let i1 ← Array.index_usize self 1#usize
  let i2 ← Array.index_usize self 2#usize
  let i3 ← Array.index_usize self 3#usize
  let tmp ← fields.fp.Fp.montgomery_reduce i i1 i2 i3 0#u64 0#u64 0#u64 0#u64
  let res := Array.repeat 32#usize 0#u8
  let (s, index_mut_back) ←
    core.array.Array.index_mut (core.ops.index.IndexMutSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) res
      { start := 0#usize, «end» := 8#usize }
  let i4 ← Array.index_usize tmp 0#usize
  let a ← lift (core.num.U64.to_le_bytes i4)
  let s1 ← lift (Array.to_slice a)
  let s2 ← core.slice.Slice.copy_from_slice core.marker.CopyU8 s s1
  let res1 := index_mut_back s2
  let (s3, index_mut_back1) ←
    core.array.Array.index_mut (core.ops.index.IndexMutSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) res1
      { start := 8#usize, «end» := 16#usize }
  let i5 ← Array.index_usize tmp 1#usize
  let a1 ← lift (core.num.U64.to_le_bytes i5)
  let s4 ← lift (Array.to_slice a1)
  let s5 ← core.slice.Slice.copy_from_slice core.marker.CopyU8 s3 s4
  let res2 := index_mut_back1 s5
  let (s6, index_mut_back2) ←
    core.array.Array.index_mut (core.ops.index.IndexMutSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) res2
      { start := 16#usize, «end» := 24#usize }
  let i6 ← Array.index_usize tmp 2#usize
  let a2 ← lift (core.num.U64.to_le_bytes i6)
  let s7 ← lift (Array.to_slice a2)
  let s8 ← core.slice.Slice.copy_from_slice core.marker.CopyU8 s6 s7
  let res3 := index_mut_back2 s8
  let (s9, index_mut_back3) ←
    core.array.Array.index_mut (core.ops.index.IndexMutSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) res3
      { start := 24#usize, «end» := 32#usize }
  let i7 ← Array.index_usize tmp 3#usize
  let a3 ← lift (core.num.U64.to_le_bytes i7)
  let s10 ← lift (Array.to_slice a3)
  let s11 ← core.slice.Slice.copy_from_slice core.marker.CopyU8 s9 s10
  ok (index_mut_back3 s11)

/-- [pasta_curves::fields::fp::{impl core::convert::From<pasta_curves::fields::fp::Fp> for [u8; 32usize]}::from]:
    Source: 'src/fields/fp.rs', lines 513:4-515:5
    Visibility: public -/
def ArrayU832.Insts.CoreConvertFromFp.from
  (value : fields.fp.Fp) : Result (Array Std.U8 32#usize) := do
  fields.fp.Fp.Insts.FfPrimeFieldArrayU832.to_repr value

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::convert::From<pasta_curves::fields::fp::Fp> for [u8; 32usize]}]
    Source: 'src/fields/fp.rs', lines 512:0-516:1 -/
@[reducible]
def ArrayU832.Insts.CoreConvertFromFp : core.convert.From (Array Std.U8
  32#usize) fields.fp.Fp := {
  from_ := ArrayU832.Insts.CoreConvertFromFp.from
}

/-- [pasta_curves::fields::fp::{impl core::convert::From<&'a pasta_curves::fields::fp::Fp> for [u8; 32usize]}::from]:
    Source: 'src/fields/fp.rs', lines 519:4-521:5
    Visibility: public -/
def ArrayU832.Insts.CoreConvertFromSharedAFp.from
  (value : fields.fp.Fp) : Result (Array Std.U8 32#usize) := do
  fields.fp.Fp.Insts.FfPrimeFieldArrayU832.to_repr value

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::convert::From<&'a pasta_curves::fields::fp::Fp> for [u8; 32usize]}]
    Source: 'src/fields/fp.rs', lines 518:0-522:1 -/
@[reducible]
def ArrayU832.Insts.CoreConvertFromSharedAFp : core.convert.From (Array Std.U8
  32#usize) fields.fp.Fp := {
  from_ := ArrayU832.Insts.CoreConvertFromSharedAFp.from
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::MulAssign<&'b pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::mul_assign]:
    Source: 'src/macros.rs', lines 148:12-150:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithMulAssignSharedBFp.mul_assign
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::MulAssign<&'b pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 146:8-151:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithMulAssignSharedBFp :
  core.ops.arith.MulAssign fields.fp.Fp fields.fp.Fp := {
  mul_assign := fields.fp.Fp.Insts.CoreOpsArithMulAssignSharedBFp.mul_assign
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::MulAssign<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::mul_assign]:
    Source: 'src/macros.rs', lines 141:12-143:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithMulAssignFp.mul_assign
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::MulAssign<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 139:8-144:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithMulAssignFp : core.ops.arith.MulAssign
  fields.fp.Fp fields.fp.Fp := {
  mul_assign := fields.fp.Fp.Insts.CoreOpsArithMulAssignFp.mul_assign
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::AddAssign<&'b pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::add_assign]:
    Source: 'src/macros.rs', lines 128:12-130:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithAddAssignSharedBFp.add_assign
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::AddAssign<&'b pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 126:8-131:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithAddAssignSharedBFp :
  core.ops.arith.AddAssign fields.fp.Fp fields.fp.Fp := {
  add_assign := fields.fp.Fp.Insts.CoreOpsArithAddAssignSharedBFp.add_assign
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::SubAssign<&'b pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::sub_assign]:
    Source: 'src/macros.rs', lines 121:12-123:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithSubAssignSharedBFp.sub_assign
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::SubAssign<&'b pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 119:8-124:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithSubAssignSharedBFp :
  core.ops.arith.SubAssign fields.fp.Fp fields.fp.Fp := {
  sub_assign := fields.fp.Fp.Insts.CoreOpsArithSubAssignSharedBFp.sub_assign
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::AddAssign<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::add_assign]:
    Source: 'src/macros.rs', lines 114:12-116:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithAddAssignFp.add_assign
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::AddAssign<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 112:8-117:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithAddAssignFp : core.ops.arith.AddAssign
  fields.fp.Fp fields.fp.Fp := {
  add_assign := fields.fp.Fp.Insts.CoreOpsArithAddAssignFp.add_assign
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::SubAssign<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::sub_assign]:
    Source: 'src/macros.rs', lines 107:12-109:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithSubAssignFp.sub_assign
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::SubAssign<pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 105:8-110:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithSubAssignFp : core.ops.arith.SubAssign
  fields.fp.Fp fields.fp.Fp := {
  sub_assign := fields.fp.Fp.Insts.CoreOpsArithSubAssignFp.sub_assign
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Mul<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 90:8-97:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithMulFpFp : core.ops.arith.Mul fields.fp.Fp
  fields.fp.Fp fields.fp.Fp := {
  mul := fields.fp.Fp.Insts.CoreOpsArithMulFpFp.mul
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Mul<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::mul]:
    Source: 'src/macros.rs', lines 76:12-78:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithMulSharedBFpFp.mul
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Mul<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 72:8-79:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithMulSharedBFpFp : core.ops.arith.Mul
  fields.fp.Fp fields.fp.Fp fields.fp.Fp := {
  mul := fields.fp.Fp.Insts.CoreOpsArithMulSharedBFpFp.mul
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Sub<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::sub]:
    Source: 'src/macros.rs', lines 56:12-58:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithSubFpFp.sub
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Sub<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 52:8-59:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithSubFpFp : core.ops.arith.Sub fields.fp.Fp
  fields.fp.Fp fields.fp.Fp := {
  sub := fields.fp.Fp.Insts.CoreOpsArithSubFpFp.sub
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Sub<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::sub]:
    Source: 'src/macros.rs', lines 38:12-40:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithSubSharedBFpFp.sub
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Sub<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 34:8-41:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithSubSharedBFpFp : core.ops.arith.Sub
  fields.fp.Fp fields.fp.Fp fields.fp.Fp := {
  sub := fields.fp.Fp.Insts.CoreOpsArithSubSharedBFpFp.sub
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Add<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 21:8-28:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithAddFpFp : core.ops.arith.Add fields.fp.Fp
  fields.fp.Fp fields.fp.Fp := {
  add := fields.fp.Fp.Insts.CoreOpsArithAddFpFp.add
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Add<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}::add]:
    Source: 'src/macros.rs', lines 7:12-9:13
    Visibility: public -/
def fields.fp.Fp.Insts.CoreOpsArithAddSharedBFpFp.add
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Add<&'b pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 3:8-10:9 -/
@[reducible]
def fields.fp.Fp.Insts.CoreOpsArithAddSharedBFpFp : core.ops.arith.Add
  fields.fp.Fp fields.fp.Fp fields.fp.Fp := {
  add := fields.fp.Fp.Insts.CoreOpsArithAddSharedBFpFp.add
}

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::pow_vartime]: loop body 1:
    Source: 'src/fields/fp.rs', lines 604:12-614:13
    Visibility: public -/
@[rust_loop_body]
def fields.fp.Fp.Insts.FfField.pow_vartime_loop0_loop0.body
  (self : fields.fp.Fp) (e : Std.U64) (res : fields.fp.Fp) (found_one : Bool)
  (i : Std.U32) :
  Result (ControlFlow (fields.fp.Fp × Bool × Std.U32) (fields.fp.Fp × Bool))
  := do
  if i > 0#u32
  then
    let i1 ← i - 1#u32
    let res1 ← if found_one
                 then fields.fp.Fp.square res
                 else ok res
    let i2 ← e >>> i1
    let i3 ← lift (i2 &&& 1#u64)
    if i3 = 1#u64
    then
      let res2 ←
        fields.fp.Fp.Insts.CoreOpsArithMulAssignSharedBFp.mul_assign res1 self
      ok (cont (res2, true, i1))
    else ok (cont (res1, found_one, i1))
  else ok (done (res, found_one))

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::pow_vartime]: loop 1:
    Source: 'src/fields/fp.rs', lines 604:12-614:13
    Visibility: public -/
@[rust_loop]
def fields.fp.Fp.Insts.FfField.pow_vartime_loop0_loop0
  (self : fields.fp.Fp) (res : fields.fp.Fp) (found_one : Bool) (e : Std.U64)
  (i : Std.U32) :
  Result (fields.fp.Fp × Bool)
  := do
  loop
    (fun (res1, found_one1, i1) =>
      fields.fp.Fp.Insts.FfField.pow_vartime_loop0_loop0.body self e res1
      found_one1 i1)
    (res, found_one, i)

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::pow_vartime]: loop body 0:
    Source: 'src/fields/fp.rs', lines 600:8-615:9
    Visibility: public -/
@[rust_loop_body]
def fields.fp.Fp.Insts.FfField.pow_vartime_loop0.body
  (self : fields.fp.Fp) (exp : Slice Std.U64) (res : fields.fp.Fp)
  (found_one : Bool) (j : Std.Usize) :
  Result (ControlFlow (fields.fp.Fp × Bool × Std.Usize) fields.fp.Fp)
  := do
  if j > 0#usize
  then
    let j1 ← j - 1#usize
    let e ← Slice.index_usize exp j1
    let (res1, found_one1) ←
      fields.fp.Fp.Insts.FfField.pow_vartime_loop0_loop0 self res found_one e
        64#u32
    ok (cont (res1, found_one1, j1))
  else ok (done res)

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::pow_vartime]: loop 0:
    Source: 'src/fields/fp.rs', lines 600:8-615:9
    Visibility: public -/
@[rust_loop]
def fields.fp.Fp.Insts.FfField.pow_vartime_loop0
  (self : fields.fp.Fp) (res : fields.fp.Fp) (found_one : Bool)
  (exp : Slice Std.U64) (j : Std.Usize) :
  Result fields.fp.Fp
  := do
  loop
    (fun (res1, found_one1, j1) =>
      fields.fp.Fp.Insts.FfField.pow_vartime_loop0.body self exp res1
      found_one1 j1)
    (res, found_one, j)

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::pow_vartime]:
    Source: 'src/fields/fp.rs', lines 590:4-617:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfField.pow_vartime
  {S : Type} (coreconvertAsRefSSliceU64Inst : core.convert.AsRef S (Slice
  Std.U64)) (self : fields.fp.Fp) (exp : S) :
  Result fields.fp.Fp
  := do
  let res ← fields.fp.Fp.one
  let exp1 ← coreconvertAsRefSSliceU64Inst.as_ref exp
  let j := Slice.len exp1
  fields.fp.Fp.Insts.FfField.pow_vartime_loop0 self res false exp1 j

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::invert]:
    Source: 'src/fields/fp.rs', lines 579:4-588:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfField.invert
  (self : fields.fp.Fp) : Result (subtle.CtOption fields.fp.Fp) := do
  let tmp ←
    fields.fp.Fp.Insts.FfField.pow_vartime (Shared0T.Insts.CoreConvertAsRef
      (Array.Insts.CoreConvertAsRefSlice Std.U64 4#usize)) self
      (Array.make 4#usize [
        11037532056220336127#u64, 2469829653914515739#u64, 0#u64,
        4611686018427387904#u64
        ])
  let f ← fields.fp.Fp.zero
  let c ← fields.fp.Fp.Insts.SubtleConstantTimeEq.ct_eq self f
  let c1 ← subtle.Choice.Insts.CoreOpsBitNotChoice.not c
  subtle.CtOption.new tmp c1

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::square]:
    Source: 'src/fields/fp.rs', lines 546:4-548:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfField.square
  (self : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.square self

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::double]:
    Source: 'src/fields/fp.rs', lines 541:4-543:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfField.double
  (self : fields.fp.Fp) : Result fields.fp.Fp := do
  fields.fp.Fp.double self

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::ONE]
    Source: 'src/fields/fp.rs', lines 526:4-526:34
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfField.ONE : Result fields.fp.Fp := fields.fp.Fp.one

/-- [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}::ZERO]
    Source: 'src/fields/fp.rs', lines 525:4-525:36
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfField.ZERO : Result fields.fp.Fp := fields.fp.Fp.zero

/-- Trait implementation: [pasta_curves::fields::fp::{impl ff::Field for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 524:0-618:1 -/
@[reducible]
def fields.fp.Fp.Insts.FfField : ff.Field fields.fp.Fp := {
  ZERO := fields.fp.Fp.Insts.FfField.ZERO
  ONE := fields.fp.Fp.Insts.FfField.ONE
  corecmpEqInst := fields.fp.Fp.Insts.CoreCmpEq
  coremarkerCopyInst := fields.fp.Fp.Insts.CoreMarkerCopy
  corecloneCloneInst := fields.fp.Fp.Insts.CoreCloneClone
  coredefaultDefaultInst := fields.fp.Fp.Insts.CoreDefaultDefault
  corefmtDebugInst := fields.fp.Fp.Insts.CoreFmtDebug
  subtleConditionallySelectableInst :=
    fields.fp.Fp.Insts.SubtleConditionallySelectable
  subtleConstantTimeEqInst := fields.fp.Fp.Insts.SubtleConstantTimeEq
  coreopsarithNegInst := fields.fp.Fp.Insts.CoreOpsArithNegFp
  coreopsarithAddInst := fields.fp.Fp.Insts.CoreOpsArithAddFpFp
  coreopsarithSubInst := fields.fp.Fp.Insts.CoreOpsArithSubFpFp
  coreopsarithMulInst := fields.fp.Fp.Insts.CoreOpsArithMulFpFp
  coreitertraitsaccumSumInst := fields.fp.Fp.Insts.CoreIterTraitsAccumSum
    (core.borrow.Borrow.Blanket fields.fp.Fp)
  coreitertraitsaccumProductInst :=
    fields.fp.Fp.Insts.CoreIterTraitsAccumProduct (core.borrow.Borrow.Blanket
    fields.fp.Fp)
  coreopsarithAddSelfSharedSelfSelfInst :=
    fields.fp.Fp.Insts.CoreOpsArithAddSharedBFpFp
  coreopsarithSubSelfSharedSelfSelfInst :=
    fields.fp.Fp.Insts.CoreOpsArithSubSharedBFpFp
  coreopsarithMulSelfSharedSelfSelfInst :=
    fields.fp.Fp.Insts.CoreOpsArithMulSharedBFpFp
  coreitertraitsaccumSumSelfSharedSelfInst :=
    fields.fp.Fp.Insts.CoreIterTraitsAccumSum (Shared0T.Insts.CoreBorrowBorrow
    fields.fp.Fp)
  coreitertraitsaccumProductSelfSharedSelfInst :=
    fields.fp.Fp.Insts.CoreIterTraitsAccumProduct
    (Shared0T.Insts.CoreBorrowBorrow fields.fp.Fp)
  coreopsarithAddAssignInst := fields.fp.Fp.Insts.CoreOpsArithAddAssignFp
  coreopsarithSubAssignInst := fields.fp.Fp.Insts.CoreOpsArithSubAssignFp
  coreopsarithMulAssignInst := fields.fp.Fp.Insts.CoreOpsArithMulAssignFp
  coreopsarithAddAssignSelfSharedSelfInst :=
    fields.fp.Fp.Insts.CoreOpsArithAddAssignSharedBFp
  coreopsarithSubAssignSelfSharedSelfInst :=
    fields.fp.Fp.Insts.CoreOpsArithSubAssignSharedBFp
  coreopsarithMulAssignSelfSharedSelfInst :=
    fields.fp.Fp.Insts.CoreOpsArithMulAssignSharedBFp
  random := fun {T0 : Type} (rand_coreRngCoreInst : rand_core.RngCore T0) =>
    fields.fp.Fp.Insts.FfField.random rand_coreRngCoreInst
  square := fields.fp.Fp.Insts.FfField.square
  double := fields.fp.Fp.Insts.FfField.double
  invert := fields.fp.Fp.Insts.FfField.invert
  sqrt_ratio := fields.fp.Fp.Insts.FfField.sqrt_ratio
  sqrt := fields.fp.Fp.Insts.FfField.sqrt
  pow_vartime := fun {S : Type} (coreconvertAsRefPSliceU64Inst :
    core.convert.AsRef S (Slice Std.U64)) =>
    fields.fp.Fp.Insts.FfField.pow_vartime coreconvertAsRefPSliceU64Inst
}

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::is_odd]:
    Source: 'src/fields/fp.rs', lines 688:4-690:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.is_odd
  (self : fields.fp.Fp) : Result subtle.Choice := do
  let a ← fields.fp.Fp.Insts.FfPrimeFieldArrayU832.to_repr self
  let i ← Array.index_usize a 0#usize
  let i1 ← lift (i &&& 1#u8)
  subtle.Choice.Insts.CoreConvertFromU8.from i1

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::from_repr]:
    Source: 'src/fields/fp.rs', lines 648:4-672:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.from_repr
  (repr : Array Std.U8 32#usize) : Result (subtle.CtOption fields.fp.Fp) := do
  let a := Array.repeat 4#usize 0#u64
  let s ←
    core.array.Array.index (core.ops.index.IndexSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) repr
      { start := 0#usize, «end» := 8#usize }
  let r ←
    core.array.TryFromArrayCopySlice.try_from 8#usize core.marker.CopyU8 s
  let a1 ← core.result.Result.unwrap core.fmt.DebugTryFromSliceError r
  let i ← lift (core.num.U64.from_le_bytes a1)
  let a2 ← Array.update a 0#usize i
  let s1 ←
    core.array.Array.index (core.ops.index.IndexSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) repr
      { start := 8#usize, «end» := 16#usize }
  let r1 ←
    core.array.TryFromArrayCopySlice.try_from 8#usize core.marker.CopyU8 s1
  let a3 ← core.result.Result.unwrap core.fmt.DebugTryFromSliceError r1
  let i1 ← lift (core.num.U64.from_le_bytes a3)
  let a4 ← Array.update a2 1#usize i1
  let s2 ←
    core.array.Array.index (core.ops.index.IndexSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) repr
      { start := 16#usize, «end» := 24#usize }
  let r2 ←
    core.array.TryFromArrayCopySlice.try_from 8#usize core.marker.CopyU8 s2
  let a5 ← core.result.Result.unwrap core.fmt.DebugTryFromSliceError r2
  let i2 ← lift (core.num.U64.from_le_bytes a5)
  let a6 ← Array.update a4 2#usize i2
  let s3 ←
    core.array.Array.index (core.ops.index.IndexSlice
      (core.slice.index.SliceIndexRangeUsizeSlice Std.U8)) repr
      { start := 24#usize, «end» := 32#usize }
  let r3 ←
    core.array.TryFromArrayCopySlice.try_from 8#usize core.marker.CopyU8 s3
  let a7 ← core.result.Result.unwrap core.fmt.DebugTryFromSliceError r3
  let i3 ← lift (core.num.U64.from_le_bytes a7)
  let a8 ← Array.update a6 3#usize i3
  let i4 ← Array.index_usize a8 0#usize
  let a9 := fields.fp.MODULUS
  let i5 ← Array.index_usize a9 0#usize
  let (_, borrow) ← arithmetic.fields.sbb i4 i5 0#u64
  let i6 ← Array.index_usize a8 1#usize
  let a10 := fields.fp.MODULUS
  let i7 ← Array.index_usize a10 1#usize
  let (_, borrow1) ← arithmetic.fields.sbb i6 i7 borrow
  let i8 ← Array.index_usize a8 2#usize
  let a11 := fields.fp.MODULUS
  let i9 ← Array.index_usize a11 2#usize
  let (_, borrow2) ← arithmetic.fields.sbb i8 i9 borrow1
  let i10 ← Array.index_usize a8 3#usize
  let a12 := fields.fp.MODULUS
  let i11 ← Array.index_usize a12 3#usize
  let (_, borrow3) ← arithmetic.fields.sbb i10 i11 borrow2
  let i12 ← lift (UScalar.cast .U8 borrow3)
  let is_some ← lift (i12 &&& 1#u8)
  let tmp ←
    fields.fp.Fp.Insts.CoreOpsArithMulAssignSharedBFp.mul_assign a8
      fields.fp.R2
  let c ← subtle.Choice.Insts.CoreConvertFromU8.from is_some
  subtle.CtOption.new tmp c

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::from_u128]:
    Source: 'src/fields/fp.rs', lines 644:4-646:5
    Visibility: public -/
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.from_u128
  (v : Std.U128) : Result fields.fp.Fp := do
  let i ← lift (UScalar.cast .U64 v)
  let i1 ← v >>> 64#i32
  let i2 ← lift (UScalar.cast .U64 i1)
  fields.fp.Fp.from_raw (Array.make 4#usize [ i, i2, 0#u64, 0#u64 ])

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::DELTA]
    Source: 'src/fields/fp.rs', lines 642:4-642:30
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.DELTA : Result fields.fp.Fp :=
  fields.fp.DELTA

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::ROOT_OF_UNITY_INV]
    Source: 'src/fields/fp.rs', lines 636:4-641:7
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.ROOT_OF_UNITY_INV
  : Result fields.fp.Fp :=
  fields.fp.Fp.from_raw
    (Array.make 4#usize [
      17345750844130103798#u64, 9556816360606991983#u64,
      13037233058361039569#u64, 3230532478545521500#u64
      ])

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::ROOT_OF_UNITY]
    Source: 'src/fields/fp.rs', lines 635:4-635:46
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.ROOT_OF_UNITY
  : Result fields.fp.Fp :=
  fields.fp.ROOT_OF_UNITY

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::S]
    Source: 'src/fields/fp.rs', lines 634:4-634:21
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.S : Std.U32 := fields.fp.S

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::MULTIPLICATIVE_GENERATOR]
    Source: 'src/fields/fp.rs', lines 633:4-633:53
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.MULTIPLICATIVE_GENERATOR
  : Result fields.fp.Fp :=
  fields.fp.GENERATOR

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::CAPACITY]
    Source: 'src/fields/fp.rs', lines 632:4-632:30
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.CAPACITY : Std.U32 := 254#u32

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::NUM_BITS]
    Source: 'src/fields/fp.rs', lines 631:4-631:30
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.NUM_BITS : Std.U32 := 255#u32

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::TWO_INV]
    Source: 'src/fields/fp.rs', lines 625:4-630:7
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.TWO_INV : Result fields.fp.Fp :=
  fields.fp.Fp.from_raw
    (Array.make 4#usize [
      14742138064964943873#u64, 1234914826957257869#u64, 0#u64,
      2305843009213693952#u64
      ])

/-- [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}::MODULUS]
    Source: 'src/fields/fp.rs', lines 623:4-624:77
    Visibility: public -/
@[global_simps, irreducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832.MODULUS : Str :=
  toStr "0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001"

/-- Trait implementation: [pasta_curves::fields::fp::{impl ff::PrimeField<[u8; 32usize]> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 620:0-691:1 -/
@[reducible]
def fields.fp.Fp.Insts.FfPrimeFieldArrayU832 : ff.PrimeField fields.fp.Fp
  (Array Std.U8 32#usize) := {
  MODULUS := ok fields.fp.Fp.Insts.FfPrimeFieldArrayU832.MODULUS
  NUM_BITS := ok fields.fp.Fp.Insts.FfPrimeFieldArrayU832.NUM_BITS
  CAPACITY := ok fields.fp.Fp.Insts.FfPrimeFieldArrayU832.CAPACITY
  TWO_INV := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.TWO_INV
  MULTIPLICATIVE_GENERATOR :=
    fields.fp.Fp.Insts.FfPrimeFieldArrayU832.MULTIPLICATIVE_GENERATOR
  S := ok fields.fp.Fp.Insts.FfPrimeFieldArrayU832.S
  ROOT_OF_UNITY := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.ROOT_OF_UNITY
  ROOT_OF_UNITY_INV :=
    fields.fp.Fp.Insts.FfPrimeFieldArrayU832.ROOT_OF_UNITY_INV
  DELTA := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.DELTA
  FieldInst := fields.fp.Fp.Insts.FfField
  coreconvertFromSelfU64Inst := fields.fp.Fp.Insts.CoreConvertFromU64
  coremarkerCopyInst := Array.Insts.CoreMarkerCopy 32#usize core.marker.CopyU8
  coredefaultDefaultInst := core.default.DefaultArray 32#usize
    core.default.DefaultU8
  coreconvertAsRefSelf_ReprSliceU8Inst := Array.Insts.CoreConvertAsRefSlice
    Std.U8 32#usize
  coreconvertAsMutSelf_ReprSliceU8Inst := Array.Insts.CoreConvertAsMutSlice
    Std.U8 32#usize
  from_u128 := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.from_u128
  from_repr := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.from_repr
  to_repr := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.to_repr
  is_odd := fields.fp.Fp.Insts.FfPrimeFieldArrayU832.is_odd
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl pasta_curves::arithmetic::fields::SqrtTableHelpers<[u8; 32usize]> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 748:0-786:1 -/
@[reducible]
def fields.fp.Fp.Insts.Pasta_curvesArithmeticFieldsSqrtTableHelpersArrayU832 :
  arithmetic.fields.SqrtTableHelpers fields.fp.Fp (Array Std.U8 32#usize) := {
  ffPrimeFieldInst := fields.fp.Fp.Insts.FfPrimeFieldArrayU832
  pow_by_t_minus1_over2 :=
    fields.fp.Fp.Insts.Pasta_curvesArithmeticFieldsSqrtTableHelpersArrayU832.pow_by_t_minus1_over2
  get_lower_32 :=
    fields.fp.Fp.Insts.Pasta_curvesArithmeticFieldsSqrtTableHelpersArrayU832.get_lower_32
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl ff::WithSmallOrderMulGroup<[u8; 32usize], 3u8> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 788:0-795:1 -/
@[reducible]
def fields.fp.Fp.Insts.FfWithSmallOrderMulGroupArrayU8323 :
  ff.WithSmallOrderMulGroup fields.fp.Fp (Array Std.U8 32#usize) 3#u8 := {
  ZETA := fields.fp.Fp.Insts.FfWithSmallOrderMulGroupArrayU8323.ZETA
  PrimeFieldInst := fields.fp.Fp.Insts.FfPrimeFieldArrayU832
}

/-- Trait implementation: [pasta_curves::fields::fp::{impl ff::FromUniformBytes<[u8; 32usize], 64usize> for pasta_curves::fields::fp::Fp}]
    Source: 'src/fields/fp.rs', lines 797:0-812:1 -/
@[reducible]
def fields.fp.Fp.Insts.FfFromUniformBytesArrayU83264 : ff.FromUniformBytes
  fields.fp.Fp (Array Std.U8 32#usize) 64#usize := {
  PrimeFieldInst := fields.fp.Fp.Insts.FfPrimeFieldArrayU832
  from_uniform_bytes :=
    fields.fp.Fp.Insts.FfFromUniformBytesArrayU83264.from_uniform_bytes
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Add<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::add]:
    Source: 'src/macros.rs', lines 16:12-18:13
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithAddFpFp.add
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithAddSharedBFpFp.add self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Add<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 12:8-19:9 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithAddFpFp : core.ops.arith.Add fields.fp.Fp
  fields.fp.Fp fields.fp.Fp := {
  add := SharedAFp.Insts.CoreOpsArithAddFpFp.add
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Sub<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::sub]:
    Source: 'src/macros.rs', lines 47:12-49:13
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithSubFpFp.sub
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithSubSharedBFpFp.sub self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Sub<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 43:8-50:9 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithSubFpFp : core.ops.arith.Sub fields.fp.Fp
  fields.fp.Fp fields.fp.Fp := {
  sub := SharedAFp.Insts.CoreOpsArithSubFpFp.sub
}

/-- [pasta_curves::fields::fp::{impl core::ops::arith::Mul<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}::mul]:
    Source: 'src/macros.rs', lines 85:12-87:13
    Visibility: public -/
def SharedAFp.Insts.CoreOpsArithMulFpFp.mul
  (self : fields.fp.Fp) (rhs : fields.fp.Fp) : Result fields.fp.Fp := do
  SharedAFp.Insts.CoreOpsArithMulSharedBFpFp.mul self rhs

/-- Trait implementation: [pasta_curves::fields::fp::{impl core::ops::arith::Mul<pasta_curves::fields::fp::Fp, pasta_curves::fields::fp::Fp> for &'a pasta_curves::fields::fp::Fp}]
    Source: 'src/macros.rs', lines 81:8-88:9 -/
@[reducible]
def SharedAFp.Insts.CoreOpsArithMulFpFp : core.ops.arith.Mul fields.fp.Fp
  fields.fp.Fp fields.fp.Fp := {
  mul := SharedAFp.Insts.CoreOpsArithMulFpFp.mul
}

end pasta_curves
