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 U, m
from proveit.linear_algebra import Unitary
from proveit.logic import Equals, Forall
from proveit.numbers import Exp, NaturalPos, one, two
from proveit.physics.quantum import m_ket_domain, var_ket_psi
from proveit.physics.quantum.circuits import unitary_gate_op
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 = [U, var_ket_psi], instance_expr = Equals(Prob(unitary_gate_op), one), domains = [Unitary(Exp(two, m)), m_ket_domain]), 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_{U \in \textrm{U}\left(2^{m}\right), \lvert \psi \rangle \in \mathbb{C}^{2^{m}}}~\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \gate{U} & \qout{U \thinspace \lvert \psi \rangle}
} \end{array}\right) = 1\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: 73
body: 4
3ExprTuple73
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 25
operands: 9
7Literal
8ExprTuple10
9ExprTuple73, 11
10Lambdaparameters: 75
body: 12
11Literal
12Conditionalvalue: 13
condition: 14
13Operationoperator: 15
operands: 16
14Operationoperator: 17
operands: 18
15Literal
16ExprTuple19, 72
17Literal
18ExprTuple20, 21
19Operationoperator: 22
operand: 27
20Operationoperator: 25
operands: 24
21Operationoperator: 25
operands: 26
22Literal
23ExprTuple27
24ExprTuple76, 28
25Literal
26ExprTuple77, 29
27Operationoperator: 30
operands: 31
28Operationoperator: 32
operand: 40
29Operationoperator: 34
operands: 35
30Literal
31ExprTuple36, 37, 38
32Literal
33ExprTuple40
34Literal
35ExprTuple39, 40
36ExprTuple41
37ExprTuple42
38ExprTuple43
39Literal
40Operationoperator: 44
operands: 45
41ExprRangelambda_map: 46
start_index: 72
end_index: 73
42ExprRangelambda_map: 47
start_index: 72
end_index: 73
43ExprRangelambda_map: 48
start_index: 72
end_index: 73
44Literal
45ExprTuple49, 73
46Lambdaparameter: 71
body: 50
47Lambdaparameter: 71
body: 51
48Lambdaparameter: 71
body: 53
49Literal
50Operationoperator: 56
operands: 54
51Operationoperator: 56
operands: 55
52ExprTuple71
53Operationoperator: 56
operands: 57
54NamedExprselement: 58
targets: 61
55NamedExprselement: 59
targets: 61
56Literal
57NamedExprselement: 60
targets: 61
58Operationoperator: 62
operands: 63
59Operationoperator: 64
operands: 65
60Operationoperator: 66
operands: 67
61Operationoperator: 68
operands: 69
62Literal
63NamedExprsstate: 77
part: 71
64Literal
65NamedExprsoperation: 76
part: 71
66Literal
67NamedExprsstate: 70
part: 71
68Literal
69ExprTuple72, 73
70Operationoperator: 74
operands: 75
71Variable
72Literal
73Variable
74Literal
75ExprTuple76, 77
76Variable
77Variable