MCPcopy Create free account
hub / github.com/PolyhedraZK/ExpanderCompilerCollection / Select

Method Select

ecgo/builder/api.go:291–308  ·  view source on GitHub ↗

--------------------------------------------------------------------------------------------- Conditionals Select yields the second variable if the first is true, otherwise yields the third variable.

(i0, i1, i2 frontend.Variable)

Source from the content-addressed store, hash-verified

289
290// Select yields the second variable if the first is true, otherwise yields the third variable.
291func (builder *builder) Select(i0, i1, i2 frontend.Variable) frontend.Variable {
292 cond := i0
293
294 // ensures that cond is boolean
295 builder.AssertIsBoolean(cond)
296
297 cst, ok := builder.constantValue(builder.toVariableId(cond))
298 if ok {
299 if cst.IsZero() {
300 return i2
301 }
302 return i1
303 }
304
305 v := builder.Sub(i1, i2)
306 w := builder.Mul(cond, v)
307 return builder.Add(w, i2)
308}
309
310// Lookup2 performs a 2-bit lookup based on the given bits and values.
311func (builder *builder) Lookup2(b0, b1 frontend.Variable, i0, i1, i2, i3 frontend.Variable) frontend.Variable {

Callers 2

CmpMethod · 0.95
mustBeLessOrEqVarMethod · 0.95

Calls 7

AssertIsBooleanMethod · 0.95
constantValueMethod · 0.95
toVariableIdMethod · 0.95
SubMethod · 0.95
MulMethod · 0.95
AddMethod · 0.95
IsZeroMethod · 0.80

Tested by

no test coverage detected