Skip to main content

Probabilistic Truncation

src/probabilistic_truncation.py
from nada_dsl import *

def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
base = SecretInteger(Input(name="base", party=party_alice))
precision = PublicUnsignedInteger(Input(name="precision", party=party_bob))
# reduce the precision of base with some randomness
# precision determines the number of bits to retain
result = base.trunc_pr(precision)
return [Output(result, "trunc_pr_result", party=party_charlie)]

Run and test the probabilistic_truncation program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run probabilistic_truncation_test

3. Test the program with inputs from the test file against the expected_outputs from the test file

nada test probabilistic_truncation_test
Feedback