logo

Expression of type Forall

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 Lambda, m, n
from proveit.logic import Bijections, Forall, 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 = Forall(instance_param_or_params = [m, var_ket_psi], instance_expr = 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), domains = [NaturalPos, m_ket_domain], condition = 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())
\forall_{m \in \mathbb{N}^+, \lvert \psi \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert \psi \rangle\right \| = 1}~\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}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 4
body: 5
4ExprTuple90, 83
5Conditionalvalue: 6
condition: 7
6Operationoperator: 40
operands: 8
7Operationoperator: 9
operands: 10
8ExprTuple11, 12
9Literal
10ExprTuple13, 14, 15
11Lambdaparameter: 89
body: 36
12Operationoperator: 16
operands: 17
13Operationoperator: 40
operands: 18
14Operationoperator: 40
operands: 19
15Operationoperator: 20
operands: 21
16Literal
17ExprTuple45, 22
18ExprTuple90, 23
19ExprTuple83, 24
20Literal
21ExprTuple25, 86
22Operationoperator: 26
operand: 32
23Literal
24Operationoperator: 28
operands: 29
25Operationoperator: 30
operand: 83
26Literal
27ExprTuple32
28Literal
29ExprTuple33, 66
30Literal
31ExprTuple83
32Lambdaparameter: 89
body: 35
33Literal
34ExprTuple89
35Conditionalvalue: 36
condition: 37
36Operationoperator: 38
operands: 39
37Operationoperator: 40
operands: 41
38Literal
39ExprTuple42, 43, 44
40Literal
41ExprTuple89, 45
42ExprTuple46
43ExprTuple47
44ExprTuple48
45Operationoperator: 80
operands: 49
46ExprRangelambda_map: 50
start_index: 86
end_index: 90
47ExprRangelambda_map: 51
start_index: 86
end_index: 90
48ExprRangelambda_map: 52
start_index: 86
end_index: 90
49ExprTuple53, 54
50Lambdaparameter: 85
body: 55
51Lambdaparameter: 85
body: 56
52Lambdaparameter: 85
body: 58
53Literal
54Operationoperator: 59
operands: 60
55Operationoperator: 64
operands: 61
56Operationoperator: 62
operands: 63
57ExprTuple85
58Operationoperator: 64
operands: 65
59Literal
60ExprTuple66, 67
61NamedExprselement: 68
targets: 71
62Literal
63NamedExprsbasis: 69
64Literal
65NamedExprselement: 70
targets: 71
66Operationoperator: 72
operands: 73
67Operationoperator: 74
operand: 86
68Operationoperator: 76
operands: 77
69Literal
70Operationoperator: 78
operands: 79
71Operationoperator: 80
operands: 81
72Literal
73ExprTuple82, 90
74Literal
75ExprTuple86
76Literal
77NamedExprsstate: 83
part: 85
78Literal
79NamedExprsstate: 84
part: 85
80Literal
81ExprTuple86, 90
82Literal
83Variable
84Operationoperator: 87
operands: 88
85Variable
86Literal
87Literal
88ExprTuple89, 90
89Variable
90Variable