Probabilistic Truncation
- Nada program
- Test file
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)]
tests/probabilistic_truncation_test.yaml
---
program: probabilistic_truncation
inputs:
precision: 4
base: 800
expected_outputs:
trunc_pr_result: 49
Run and test the probabilistic_truncation program
1. Open "Nada by Example"
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