logo

Expression of type Conditional

from the theory of proveit.physics.quantum.circuits

In [1]:
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 Conditional, m, n
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Abs, Exp, two
from proveit.physics.quantum import NumBra, Qmult, m_bit_interval, m_ket_domain, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import register_meas
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Conditional(Forall(instance_param_or_params = [var_ket_psi], instance_expr = Equals(Prob(register_meas), Exp(Abs(Qmult(NumBra(n, m), var_ket_psi)), two)), domain = m_ket_domain, condition = normalized_var_ket_psi), InSet(n, m_bit_interval))
expr:
In [3]:
# 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")
Passed sanity check: expr matches stored_expr
In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
\left\{\forall_{\lvert \psi \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert \psi \rangle\right \| = 1}~\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert \psi \rangle} & \meter & \multiqout{3}{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \measure{\begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}}
} \end{array}\right) = \left|{_{m}}\langle n \rvert \thinspace \lvert \psi \rangle\right|^{2}\right) \textrm{ if } n \in \{0~\ldotp \ldotp~2^{m} - 1\}\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operand: 6
2Operationoperator: 27
operands: 5
3Literal
4ExprTuple6
5ExprTuple89, 7
6Lambdaparameter: 83
body: 8
7Operationoperator: 81
operands: 9
8Conditionalvalue: 10
condition: 11
9ExprTuple12, 13
10Operationoperator: 29
operands: 14
11Operationoperator: 15
operands: 16
12Literal
13Operationoperator: 17
operands: 18
14ExprTuple19, 20
15Literal
16ExprTuple21, 22
17Literal
18ExprTuple50, 23
19Operationoperator: 24
operand: 33
20Operationoperator: 56
operands: 26
21Operationoperator: 27
operands: 28
22Operationoperator: 29
operands: 30
23Operationoperator: 31
operand: 86
24Literal
25ExprTuple33
26ExprTuple34, 62
27Literal
28ExprTuple83, 35
29Literal
30ExprTuple36, 86
31Literal
32ExprTuple86
33Operationoperator: 37
operands: 38
34Operationoperator: 39
operand: 48
35Operationoperator: 41
operands: 42
36Operationoperator: 43
operand: 83
37Literal
38ExprTuple45, 46, 47
39Literal
40ExprTuple48
41Literal
42ExprTuple49, 50
43Literal
44ExprTuple83
45ExprTuple51
46ExprTuple52
47ExprTuple53
48Operationoperator: 54
operands: 55
49Literal
50Operationoperator: 56
operands: 57
51ExprRangelambda_map: 58
start_index: 86
end_index: 90
52ExprRangelambda_map: 59
start_index: 86
end_index: 90
53ExprRangelambda_map: 60
start_index: 86
end_index: 90
54Literal
55ExprTuple61, 83
56Literal
57ExprTuple62, 90
58Lambdaparameter: 85
body: 63
59Lambdaparameter: 85
body: 64
60Lambdaparameter: 85
body: 66
61Operationoperator: 67
operands: 88
62Literal
63Operationoperator: 71
operands: 68
64Operationoperator: 69
operands: 70
65ExprTuple85
66Operationoperator: 71
operands: 72
67Literal
68NamedExprselement: 73
targets: 76
69Literal
70NamedExprsbasis: 74
71Literal
72NamedExprselement: 75
targets: 76
73Operationoperator: 77
operands: 78
74Literal
75Operationoperator: 79
operands: 80
76Operationoperator: 81
operands: 82
77Literal
78NamedExprsstate: 83
part: 85
79Literal
80NamedExprsstate: 84
part: 85
81Literal
82ExprTuple86, 90
83Variable
84Operationoperator: 87
operands: 88
85Variable
86Literal
87Literal
88ExprTuple89, 90
89Variable
90Variable