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, b
from proveit.logic import And, Equals, InSet, Set
from proveit.numbers import Abs, Exp, one, two, zero
from proveit.physics.quantum import Bra, Qmult, QubitSpace, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import qubit_meas
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Conditional(Equals(Prob(qubit_meas), Exp(Abs(Qmult(Bra(b), var_ket_psi)), two)), And(InSet(var_ket_psi, QubitSpace), InSet(b, Set(zero, one)), 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{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right) = \left|\langle b \rvert \thinspace \lvert \psi \rangle\right|^{2} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2} ,  b \in \left\{0, 1\right\} ,  \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: 18
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9, 10
6Operationoperator: 11
operand: 20
7Operationoperator: 13
operands: 14
8Operationoperator: 16
operands: 15
9Operationoperator: 16
operands: 17
10Operationoperator: 18
operands: 19
11Literal
12ExprTuple20
13Literal
14ExprTuple21, 40
15ExprTuple55, 22
16Literal
17ExprTuple61, 23
18Literal
19ExprTuple24, 42
20Operationoperator: 25
operands: 26
21Operationoperator: 27
operand: 38
22Operationoperator: 29
operands: 30
23Operationoperator: 31
operands: 32
24Operationoperator: 33
operand: 55
25Literal
26ExprTuple35, 36, 37
27Literal
28ExprTuple38
29Literal
30ExprTuple39, 40
31Literal
32ExprTuple41, 42
33Literal
34ExprTuple55
35ExprTuple43
36ExprTuple44
37ExprTuple45
38Operationoperator: 46
operands: 47
39Literal
40Literal
41Literal
42Literal
43Operationoperator: 48
operands: 49
44Operationoperator: 50
operands: 51
45Operationoperator: 52
operands: 53
46Literal
47ExprTuple54, 55
48Literal
49NamedExprsstate: 55
50Literal
51NamedExprsbasis: 56
52Literal
53NamedExprsstate: 57
54Operationoperator: 58
operand: 61
55Variable
56Literal
57Operationoperator: 59
operand: 61
58Literal
59Literal
60ExprTuple61
61Variable