INNER CODE UNIT · Python
prefix_or1
lschoe/mpyc · demos/PrefixOrExplained.py:63
def prefix_or1(x):
return list(mpyc.mpctools.accumulate(x, operator.or_))
# Given a list of bits `x`, both `prefix_or0(x)` and `prefix_or1(x)` compute the or over all (nonempty) prefixes of `x`.
# In[5]:
x = [0, 0, 0, 1, 0, 0, 1, 0]
print(prefix_or0(x))
print(prefix_or1(x))
# Once we reach the first (leftmost) `1` in the input, this bit and all succeeding bits will be `1` in the output.
# To see the difference between `prefix_or0(x)` and `prefix_or1(x)` when used in multiparty computation, we introduce a slightly modified version of MPyC's secure integer type. This way we count the total number of interactive evaluations of the operator `|` (same as `operator.or_`), which we will refer to as the **or-complexity**. Moreover, we keep track of the depth of each secure integer value computed along the way, which we will refer to as its **or-depth**. By definition, the input values are at depth 0. Each (intermediate) value resulting from an evaluation of `|` is at depth one more than the largest depth of its inputs, provided both inputs are secure integers.