Multiplicative Inverse

In this section we will compute exact multiplicative inverses with respect to the field. Note that this is not the same as division, which produces approximate results.

In this case the multiplicative inverse we are dealing with is associated specifically with the field, and not relative to the encoded or decoded values that we create with our fixed point arithmetic. Thus, we will be working with the Identity encoding that does not encode or decode values.

In this example, we generate random field values, reveal them, compute their multiplicative inverses, reveal those, and perform an untruncated multiplication, all of which yield the field value \(1\), showing that the inverses are correct for the field.

[1]:
import logging

import numpy

from cicada.additive import AdditiveProtocolSuite
from cicada.communicator import SocketCommunicator
from cicada.encoding import Identity
from cicada.logging import Logger

logging.basicConfig(level=logging.INFO)

def main(communicator):
    log = Logger(logging.getLogger(), communicator)
    protocol = AdditiveProtocolSuite(communicator)

    for i in range(3):
        log.info(f"*" * 60, src=0)

        random_share = protocol.field_uniform()
        random = protocol.reveal(random_share, encoding=Identity())
        log.info(f"Player {communicator.rank} random value:           {random}", src=0)

        inverse_share = protocol.multiplicative_inverse(random_share)
        inverse = protocol.reveal(inverse_share, encoding=Identity())
        log.info(f"Player {communicator.rank} multiplicative inverse: {inverse}", src=0)

        product_share = protocol.field_multiply(random_share, inverse_share)
        product = protocol.reveal(product_share, encoding=Identity())
        log.info(f"Player {communicator.rank} product:                {product}", src=0)

SocketCommunicator.run(world_size=3, fn=main);
INFO:root:************************************************************
INFO:root:Player 0 random value:           4415459484255806218
INFO:root:Player 0 multiplicative inverse: 1110914679579980136
INFO:root:Player 0 product:                1
INFO:root:************************************************************
INFO:root:Player 0 random value:           12865292195403216087
INFO:root:Player 0 multiplicative inverse: 8281206491458532839
INFO:root:Player 0 product:                1
INFO:root:************************************************************
INFO:root:Player 0 random value:           16098991628576644671
INFO:root:Player 0 multiplicative inverse: 8756623746587136875
INFO:root:Player 0 product:                1