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 Forall, InClass, 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
from proveit.statistics import SampleSpaces
In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [m, var_ket_psi], instance_expr = InClass(SetOfAll(instance_param_or_params = [n], instance_element = register_meas, domain = m_bit_interval), SampleSpaces), 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(\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\}} \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces}\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
4ExprTuple88, 81
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple14, 15, 16
12Operationoperator: 17
operand: 23
13Literal
14Operationoperator: 38
operands: 19
15Operationoperator: 38
operands: 20
16Operationoperator: 21
operands: 22
17Literal
18ExprTuple23
19ExprTuple88, 24
20ExprTuple81, 25
21Literal
22ExprTuple26, 84
23Lambdaparameter: 87
body: 28
24Literal
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operand: 81
27ExprTuple87
28Conditionalvalue: 33
condition: 34
29Literal
30ExprTuple35, 64
31Literal
32ExprTuple81
33Operationoperator: 36
operands: 37
34Operationoperator: 38
operands: 39
35Literal
36Literal
37ExprTuple40, 41, 42
38Literal
39ExprTuple87, 43
40ExprTuple44
41ExprTuple45
42ExprTuple46
43Operationoperator: 78
operands: 47
44ExprRangelambda_map: 48
start_index: 84
end_index: 88
45ExprRangelambda_map: 49
start_index: 84
end_index: 88
46ExprRangelambda_map: 50
start_index: 84
end_index: 88
47ExprTuple51, 52
48Lambdaparameter: 83
body: 53
49Lambdaparameter: 83
body: 54
50Lambdaparameter: 83
body: 56
51Literal
52Operationoperator: 57
operands: 58
53Operationoperator: 62
operands: 59
54Operationoperator: 60
operands: 61
55ExprTuple83
56Operationoperator: 62
operands: 63
57Literal
58ExprTuple64, 65
59NamedExprselement: 66
targets: 69
60Literal
61NamedExprsbasis: 67
62Literal
63NamedExprselement: 68
targets: 69
64Operationoperator: 70
operands: 71
65Operationoperator: 72
operand: 84
66Operationoperator: 74
operands: 75
67Literal
68Operationoperator: 76
operands: 77
69Operationoperator: 78
operands: 79
70Literal
71ExprTuple80, 88
72Literal
73ExprTuple84
74Literal
75NamedExprsstate: 81
part: 83
76Literal
77NamedExprsstate: 82
part: 83
78Literal
79ExprTuple84, 88
80Literal
81Variable
82Operationoperator: 85
operands: 86
83Variable
84Literal
85Literal
86ExprTuple87, 88
87Variable
88Variable