import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import ExprRange, Variable, VertExprArray
from proveit.linear_algebra import TensorProd
from proveit.logic import Equals
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE, _Psi_circuit, _Psi_ket, _U, _ket_u, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(_t, one)
sub_expr3 = Add(_t, _s)
sub_expr4 = Interval(one, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = sub_expr4)
sub_expr6 = MultiQubitElem(element = Output(state = TensorProd(_Psi_ket, _ket_u), part = sub_expr1), targets = sub_expr4)
expr = Equals(Prob(_Psi_circuit), Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr2, sub_expr3)), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, _t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, sub_expr6, one, _t).with_wrapping_at(2,6), ExprRange(sub_expr1, sub_expr6, sub_expr2, sub_expr3).with_wrapping_at(2,6)]))))
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
stored_expr.style_options()
# display the expression information
stored_expr.expr_info()