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, Lambda, m, n
from proveit.logic import And, Bijections, InSet, SetOfAll
from proveit.numbers import NaturalPos
from proveit.physics.quantum import m_bit_interval, m_ket_domain, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import register_meas
In [2]:
# build up the expression from sub-expressions
expr = Conditional(InSet(Lambda(n, register_meas), Bijections(m_bit_interval, SetOfAll(instance_param_or_params = [n], instance_element = register_meas, domain = m_bit_interval))).with_wrapping_at(2), And(InSet(m, NaturalPos), 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\{\begin{array}{c} \begin{array}{l} \left[n \mapsto \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)\right] \in  \\ \left[\{0~\ldotp \ldotp~2^{m} - 1\} \xrightarrow[\text{onto}]{\text{1-to-1}} \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\}_{n \in \{0~\ldotp \ldotp~2^{m} - 1\}}\right] \end{array} \end{array} \textrm{ if } m \in \mathbb{N}^+ ,  \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: 35
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9, 10
6Lambdaparameter: 84
body: 31
7Operationoperator: 11
operands: 12
8Operationoperator: 35
operands: 13
9Operationoperator: 35
operands: 14
10Operationoperator: 15
operands: 16
11Literal
12ExprTuple40, 17
13ExprTuple85, 18
14ExprTuple78, 19
15Literal
16ExprTuple20, 81
17Operationoperator: 21
operand: 27
18Literal
19Operationoperator: 23
operands: 24
20Operationoperator: 25
operand: 78
21Literal
22ExprTuple27
23Literal
24ExprTuple28, 61
25Literal
26ExprTuple78
27Lambdaparameter: 84
body: 30
28Literal
29ExprTuple84
30Conditionalvalue: 31
condition: 32
31Operationoperator: 33
operands: 34
32Operationoperator: 35
operands: 36
33Literal
34ExprTuple37, 38, 39
35Literal
36ExprTuple84, 40
37ExprTuple41
38ExprTuple42
39ExprTuple43
40Operationoperator: 75
operands: 44
41ExprRangelambda_map: 45
start_index: 81
end_index: 85
42ExprRangelambda_map: 46
start_index: 81
end_index: 85
43ExprRangelambda_map: 47
start_index: 81
end_index: 85
44ExprTuple48, 49
45Lambdaparameter: 80
body: 50
46Lambdaparameter: 80
body: 51
47Lambdaparameter: 80
body: 53
48Literal
49Operationoperator: 54
operands: 55
50Operationoperator: 59
operands: 56
51Operationoperator: 57
operands: 58
52ExprTuple80
53Operationoperator: 59
operands: 60
54Literal
55ExprTuple61, 62
56NamedExprselement: 63
targets: 66
57Literal
58NamedExprsbasis: 64
59Literal
60NamedExprselement: 65
targets: 66
61Operationoperator: 67
operands: 68
62Operationoperator: 69
operand: 81
63Operationoperator: 71
operands: 72
64Literal
65Operationoperator: 73
operands: 74
66Operationoperator: 75
operands: 76
67Literal
68ExprTuple77, 85
69Literal
70ExprTuple81
71Literal
72NamedExprsstate: 78
part: 80
73Literal
74NamedExprsstate: 79
part: 80
75Literal
76ExprTuple81, 85
77Literal
78Variable
79Operationoperator: 82
operands: 83
80Variable
81Literal
82Literal
83ExprTuple84, 85
84Variable
85Variable