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 And, Equals, InSet
from proveit.numbers import Abs, Exp, two
from proveit.physics.quantum import NumBra, Qmult, 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(Equals(Prob(register_meas), Exp(Abs(Qmult(NumBra(n, m), var_ket_psi)), two)), And(InSet(var_ket_psi, m_ket_domain), normalized_var_ket_psi))
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\{\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} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert \psi \rangle\right \| = 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: 15
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9
6Operationoperator: 10
operand: 17
7Operationoperator: 40
operands: 12
8Operationoperator: 13
operands: 14
9Operationoperator: 15
operands: 16
10Literal
11ExprTuple17
12ExprTuple18, 46
13Literal
14ExprTuple67, 19
15Literal
16ExprTuple20, 70
17Operationoperator: 21
operands: 22
18Operationoperator: 23
operand: 32
19Operationoperator: 25
operands: 26
20Operationoperator: 27
operand: 67
21Literal
22ExprTuple29, 30, 31
23Literal
24ExprTuple32
25Literal
26ExprTuple33, 34
27Literal
28ExprTuple67
29ExprTuple35
30ExprTuple36
31ExprTuple37
32Operationoperator: 38
operands: 39
33Literal
34Operationoperator: 40
operands: 41
35ExprRangelambda_map: 42
start_index: 70
end_index: 74
36ExprRangelambda_map: 43
start_index: 70
end_index: 74
37ExprRangelambda_map: 44
start_index: 70
end_index: 74
38Literal
39ExprTuple45, 67
40Literal
41ExprTuple46, 74
42Lambdaparameter: 69
body: 47
43Lambdaparameter: 69
body: 48
44Lambdaparameter: 69
body: 50
45Operationoperator: 51
operands: 72
46Literal
47Operationoperator: 55
operands: 52
48Operationoperator: 53
operands: 54
49ExprTuple69
50Operationoperator: 55
operands: 56
51Literal
52NamedExprselement: 57
targets: 60
53Literal
54NamedExprsbasis: 58
55Literal
56NamedExprselement: 59
targets: 60
57Operationoperator: 61
operands: 62
58Literal
59Operationoperator: 63
operands: 64
60Operationoperator: 65
operands: 66
61Literal
62NamedExprsstate: 67
part: 69
63Literal
64NamedExprsstate: 68
part: 69
65Literal
66ExprTuple70, 74
67Variable
68Operationoperator: 71
operands: 72
69Variable
70Literal
71Literal
72ExprTuple73, 74
73Variable
74Variable