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, 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 = [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)
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_{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]
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: 7
operand: 2
1ExprTuple2
2Lambdaparameter: 93
body: 4
3ExprTuple93
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 31
operands: 9
7Literal
8ExprTuple10
9ExprTuple93, 11
10Lambdaparameter: 87
body: 12
11Operationoperator: 85
operands: 13
12Conditionalvalue: 14
condition: 15
13ExprTuple16, 17
14Operationoperator: 33
operands: 18
15Operationoperator: 19
operands: 20
16Literal
17Operationoperator: 21
operands: 22
18ExprTuple23, 24
19Literal
20ExprTuple25, 26
21Literal
22ExprTuple54, 27
23Operationoperator: 28
operand: 37
24Operationoperator: 60
operands: 30
25Operationoperator: 31
operands: 32
26Operationoperator: 33
operands: 34
27Operationoperator: 35
operand: 90
28Literal
29ExprTuple37
30ExprTuple38, 66
31Literal
32ExprTuple87, 39
33Literal
34ExprTuple40, 90
35Literal
36ExprTuple90
37Operationoperator: 41
operands: 42
38Operationoperator: 43
operand: 52
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operand: 87
41Literal
42ExprTuple49, 50, 51
43Literal
44ExprTuple52
45Literal
46ExprTuple53, 54
47Literal
48ExprTuple87
49ExprTuple55
50ExprTuple56
51ExprTuple57
52Operationoperator: 58
operands: 59
53Literal
54Operationoperator: 60
operands: 61
55ExprRangelambda_map: 62
start_index: 90
end_index: 94
56ExprRangelambda_map: 63
start_index: 90
end_index: 94
57ExprRangelambda_map: 64
start_index: 90
end_index: 94
58Literal
59ExprTuple65, 87
60Literal
61ExprTuple66, 94
62Lambdaparameter: 89
body: 67
63Lambdaparameter: 89
body: 68
64Lambdaparameter: 89
body: 70
65Operationoperator: 71
operands: 92
66Literal
67Operationoperator: 75
operands: 72
68Operationoperator: 73
operands: 74
69ExprTuple89
70Operationoperator: 75
operands: 76
71Literal
72NamedExprselement: 77
targets: 80
73Literal
74NamedExprsbasis: 78
75Literal
76NamedExprselement: 79
targets: 80
77Operationoperator: 81
operands: 82
78Literal
79Operationoperator: 83
operands: 84
80Operationoperator: 85
operands: 86
81Literal
82NamedExprsstate: 87
part: 89
83Literal
84NamedExprsstate: 88
part: 89
85Literal
86ExprTuple90, 94
87Variable
88Operationoperator: 91
operands: 92
89Variable
90Literal
91Literal
92ExprTuple93, 94
93Variable
94Variable