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 m, n
from proveit.logic import Equals, Forall
from proveit.numbers import Abs, Exp, NaturalPos, 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 = Forall(instance_param_or_params = [m], instance_expr = Forall(instance_param_or_params = [n], instance_expr = 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), domain = m_bit_interval), domain = NaturalPos)
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}^+}~\left[\forall_{n \in \{0~\ldotp \ldotp~2^{m} - 1\}}~\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)\right]\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: 15
operand: 2
1ExprTuple2
2Lambdaparameter: 102
body: 4
3ExprTuple102
4Conditionalvalue: 5
condition: 6
5Operationoperator: 15
operand: 9
6Operationoperator: 39
operands: 8
7ExprTuple9
8ExprTuple102, 10
9Lambdaparameter: 101
body: 12
10Literal
11ExprTuple101
12Conditionalvalue: 13
condition: 14
13Operationoperator: 15
operand: 18
14Operationoperator: 39
operands: 17
15Literal
16ExprTuple18
17ExprTuple101, 19
18Lambdaparameter: 95
body: 20
19Operationoperator: 93
operands: 21
20Conditionalvalue: 22
condition: 23
21ExprTuple24, 25
22Operationoperator: 41
operands: 26
23Operationoperator: 27
operands: 28
24Literal
25Operationoperator: 29
operands: 30
26ExprTuple31, 32
27Literal
28ExprTuple33, 34
29Literal
30ExprTuple62, 35
31Operationoperator: 36
operand: 45
32Operationoperator: 68
operands: 38
33Operationoperator: 39
operands: 40
34Operationoperator: 41
operands: 42
35Operationoperator: 43
operand: 98
36Literal
37ExprTuple45
38ExprTuple46, 74
39Literal
40ExprTuple95, 47
41Literal
42ExprTuple48, 98
43Literal
44ExprTuple98
45Operationoperator: 49
operands: 50
46Operationoperator: 51
operand: 60
47Operationoperator: 53
operands: 54
48Operationoperator: 55
operand: 95
49Literal
50ExprTuple57, 58, 59
51Literal
52ExprTuple60
53Literal
54ExprTuple61, 62
55Literal
56ExprTuple95
57ExprTuple63
58ExprTuple64
59ExprTuple65
60Operationoperator: 66
operands: 67
61Literal
62Operationoperator: 68
operands: 69
63ExprRangelambda_map: 70
start_index: 98
end_index: 102
64ExprRangelambda_map: 71
start_index: 98
end_index: 102
65ExprRangelambda_map: 72
start_index: 98
end_index: 102
66Literal
67ExprTuple73, 95
68Literal
69ExprTuple74, 102
70Lambdaparameter: 97
body: 75
71Lambdaparameter: 97
body: 76
72Lambdaparameter: 97
body: 78
73Operationoperator: 79
operands: 100
74Literal
75Operationoperator: 83
operands: 80
76Operationoperator: 81
operands: 82
77ExprTuple97
78Operationoperator: 83
operands: 84
79Literal
80NamedExprselement: 85
targets: 88
81Literal
82NamedExprsbasis: 86
83Literal
84NamedExprselement: 87
targets: 88
85Operationoperator: 89
operands: 90
86Literal
87Operationoperator: 91
operands: 92
88Operationoperator: 93
operands: 94
89Literal
90NamedExprsstate: 95
part: 97
91Literal
92NamedExprsstate: 96
part: 97
93Literal
94ExprTuple98, 102
95Variable
96Operationoperator: 99
operands: 100
97Variable
98Literal
99Literal
100ExprTuple101, 102
101Variable
102Variable