From 8e688474e11f3b01344da93d76009c0e0736820f Mon Sep 17 00:00:00 2001 From: siq1 Date: Sat, 2 Nov 2024 01:43:30 +0800 Subject: [PATCH] implement get random value api --- expander_compiler/src/frontend/api.rs | 1 + expander_compiler/src/frontend/builder.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/expander_compiler/src/frontend/api.rs b/expander_compiler/src/frontend/api.rs index 08b7f8a..d0bad08 100644 --- a/expander_compiler/src/frontend/api.rs +++ b/expander_compiler/src/frontend/api.rs @@ -41,6 +41,7 @@ pub trait BasicAPI { x: impl ToVariableOrValue, y: impl ToVariableOrValue, ); + fn get_random_value(&mut self) -> Variable; } pub trait UnconstrainedAPI { diff --git a/expander_compiler/src/frontend/builder.rs b/expander_compiler/src/frontend/builder.rs index ca42c27..eba6748 100644 --- a/expander_compiler/src/frontend/builder.rs +++ b/expander_compiler/src/frontend/builder.rs @@ -288,6 +288,12 @@ impl BasicAPI for Builder { let diff = self.sub(x, y); self.assert_is_non_zero(diff); } + + fn get_random_value(&mut self) -> Variable { + self.instructions + .push(SourceInstruction::ConstantLike(Coef::Random)); + self.new_var() + } } // write macro rules for unconstrained binary op definition @@ -436,6 +442,10 @@ impl BasicAPI for RootBuilder { ) { self.last_builder().assert_is_different(x, y) } + + fn get_random_value(&mut self) -> Variable { + self.last_builder().get_random_value() + } } impl RootBuilder {