Skip to main content

Arithmetic and Logic

Nada programs can work with common arithmetic and logic values (such as integers and booleans) and operations (such as addition and conditional expressions).

Integers

The example below computes the revenue generated from the sales of two categories of product. In this example, all inputs are of type SecretInteger, so the result revenue is also of this type.

Suppose that the price information is public. In this case, revenue is still of type SecretInteger because the quantity information is private. If revenue were of type PublicInteger, it would (in some cases) be possible to determine the quantity information from the revenue by working backwards.

What about integer values that appear in the program as literals (i.e., they are not secret or public inputs) but are used within calculations involving inputs? These should be of type Integer.

Boolean Values and Comparison of Integers

Comparison operations can be applied to integers. Such comparison expressions evaluate to Nada boolean values. Whether this resulting value is secret depends on whether the integers being compared are secret. Furthermore, Nada boolean values support the if_else method, which implements a variant of the ternary conditional operator that can work with Nada values (even if they are secret).

The example below leverages both an integer comparison operator and the ternary operator to determine the larger of two secret inputs.

Built-in Python Constants and Operations

Because Nada is a DSL embedded inside Python, built-in constants of type int and bool (and the operators associated with these types) can be used directly. However, it is important to understand that these cannot be used interchangeably or mixed. The example below demonstrates both correct and incorrect usage of built-in and Nada values.