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_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 = [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)
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_{\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)
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
3Lambdaparameter: 71
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 19
operands: 7
6Operationoperator: 8
operands: 9
7ExprTuple10, 11
8Literal
9ExprTuple12, 13
10Operationoperator: 14
operand: 21
11Operationoperator: 44
operands: 16
12Operationoperator: 17
operands: 18
13Operationoperator: 19
operands: 20
14Literal
15ExprTuple21
16ExprTuple22, 50
17Literal
18ExprTuple71, 23
19Literal
20ExprTuple24, 74
21Operationoperator: 25
operands: 26
22Operationoperator: 27
operand: 36
23Operationoperator: 29
operands: 30
24Operationoperator: 31
operand: 71
25Literal
26ExprTuple33, 34, 35
27Literal
28ExprTuple36
29Literal
30ExprTuple37, 38
31Literal
32ExprTuple71
33ExprTuple39
34ExprTuple40
35ExprTuple41
36Operationoperator: 42
operands: 43
37Literal
38Operationoperator: 44
operands: 45
39ExprRangelambda_map: 46
start_index: 74
end_index: 78
40ExprRangelambda_map: 47
start_index: 74
end_index: 78
41ExprRangelambda_map: 48
start_index: 74
end_index: 78
42Literal
43ExprTuple49, 71
44Literal
45ExprTuple50, 78
46Lambdaparameter: 73
body: 51
47Lambdaparameter: 73
body: 52
48Lambdaparameter: 73
body: 54
49Operationoperator: 55
operands: 76
50Literal
51Operationoperator: 59
operands: 56
52Operationoperator: 57
operands: 58
53ExprTuple73
54Operationoperator: 59
operands: 60
55Literal
56NamedExprselement: 61
targets: 64
57Literal
58NamedExprsbasis: 62
59Literal
60NamedExprselement: 63
targets: 64
61Operationoperator: 65
operands: 66
62Literal
63Operationoperator: 67
operands: 68
64Operationoperator: 69
operands: 70
65Literal
66NamedExprsstate: 71
part: 73
67Literal
68NamedExprsstate: 72
part: 73
69Literal
70ExprTuple74, 78
71Variable
72Operationoperator: 75
operands: 76
73Variable
74Literal
75Literal
76ExprTuple77, 78
77Variable
78Variable