Skip to content

Commit

Permalink
Revert "simplify at touch"
Browse files Browse the repository at this point in the history
This reverts commit 2ba3e70.
  • Loading branch information
alexander-camuto committed Nov 9, 2024
1 parent 2ba3e70 commit d0e37cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/circuit/ops/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ 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 @@ -304,10 +315,10 @@ pub fn sqrt<F: PrimeField + TensorType + PartialOrd + std::hash::Hash>(
region.increment(claimed_output.len());

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

// rescaled input
let rescaled_input = pairwise(config, region, &[input.clone(), unit_scale], BaseOp::Mult)?;
Expand Down Expand Up @@ -4817,6 +4828,8 @@ 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: 8 additions & 2 deletions src/tensor/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ pub fn get_rep(
return Err(DecompositionError::TooLarge(*x, base, n));
}
let mut rep = vec![0; n + 1];
// sign bit, we omit 0 as it is not needed in our representation
rep[0] = if *x < 0 { -1 } else { 1 };
// sign bit
rep[0] = if *x < 0 {
-1
} else if *x > 0 {
1
} else {
0
};

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

0 comments on commit d0e37cc

Please sign in to comment.