import numpy as np
from concrete import fhe
@fhe.module()
class PowerWithoutComposition:
@fhe.function({"x": "encrypted"})
def square(x):
return x ** 2
@fhe.function({"x": "encrypted"})
def cube(x):
return x ** 3
without_composition = PowerWithoutComposition.compile(
{
"square": fhe.inputset(fhe.uint2),
"cube": fhe.inputset(fhe.uint4),
}
)
print(f"without composition -> {int(without_composition.complexity):>10_} complexity")
@fhe.module()
class PowerWithComposition:
@fhe.function({"x": "encrypted"})
def square(x):
return x ** 2
@fhe.function({"x": "encrypted"})
def cube(x):
return x ** 3
composition = fhe.Wired(
[
fhe.Wire(fhe.Output(square, 0), fhe.Input(cube, 0))
]
)
with_composition = PowerWithComposition.compile(
{
"square": fhe.inputset(fhe.uint2),
"cube": fhe.inputset(fhe.uint4),
}
)
print(f" with composition -> {int(with_composition.complexity):>10_} complexity")