Skip to content

Commit

Permalink
simplify at touch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto committed Nov 9, 2024
1 parent 13f9a61 commit 2ba3e70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
19 changes: 3 additions & 16 deletions src/circuit/ops/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ pub fn diff_less_than<F: PrimeField + TensorType + PartialOrd + std::hash::Hash>
Ok(())
}

fn is_positive<F: PrimeField + TensorType + PartialOrd + std::hash::Hash>(
config: &BaseConfig<F>,
region: &mut RegionCtx<F>,
value: &[ValTensor<F>; 1],
) -> Result<ValTensor<F>, CircuitError> {
let neg_one = create_constant_tensor(integer_rep_to_felt(-1), 1);
let is_negative = equals(config, region, &[value[0].clone(), neg_one])?;

not(config, region, &[is_negative])
}

/// Div accumulated layout
pub(crate) fn div<F: PrimeField + TensorType + PartialOrd + std::hash::Hash>(
config: &BaseConfig<F>,
Expand Down Expand Up @@ -315,10 +304,10 @@ pub fn sqrt<F: PrimeField + TensorType + PartialOrd + std::hash::Hash>(
region.increment(claimed_output.len());

// assert value is positive
let is_positive = is_positive(config, region, &[claimed_output.clone()])?;
let ones = create_constant_tensor(F::ONE, is_positive.len());
let sign = sign(config, region, &[claimed_output.clone()])?;
let ones = create_constant_tensor(F::ONE, sign.len());
// assert the sign is positive
enforce_equality(config, region, &[is_positive, ones])?;
enforce_equality(config, region, &[sign, ones])?;

// rescaled input
let rescaled_input = pairwise(config, region, &[input.clone(), unit_scale], BaseOp::Mult)?;
Expand Down Expand Up @@ -4828,8 +4817,6 @@ pub fn ln<F: PrimeField + TensorType + PartialOrd + std::hash::Hash>(
comparison_unit.reshape(is_closest.dims())?;
let assigned_unit = region.assign(&config.custom_gates.inputs[1], &comparison_unit)?;

println!("is_closest {}", is_closest.show());

enforce_equality(config, region, &[is_closest, assigned_unit])?;

// get a linear interpolation now
Expand Down
10 changes: 2 additions & 8 deletions src/tensor/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ pub fn get_rep(
return Err(DecompositionError::TooLarge(*x, base, n));
}
let mut rep = vec![0; n + 1];
// sign bit
rep[0] = if *x < 0 {
-1
} else if *x > 0 {
1
} else {
0
};
// sign bit, we omit 0 as it is not needed in our representation
rep[0] = if *x < 0 { -1 } else { 1 };

let mut x = x.abs();
//
Expand Down

0 comments on commit 2ba3e70

Please sign in to comment.