logo

Expression of type Conditional

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 Conditional, b
from proveit.logic import And, InClass, InSet, Set, SetOfAll
from proveit.numbers import one, zero
from proveit.physics.quantum import QubitSpace, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import qubit_meas
from proveit.statistics import SampleSpaces
In [2]:
# build up the expression from sub-expressions
expr = Conditional(InClass(SetOfAll(instance_param_or_params = [b], instance_element = qubit_meas, domain = Set(zero, one)), SampleSpaces), And(InSet(var_ket_psi, QubitSpace), 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())
\left\{\left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right\}_{b \in \left\{0, 1\right\}} \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2} ,  \left \|\lvert \psi \rangle\right \| = 1\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple9, 10
7Operationoperator: 11
operand: 16
8Literal
9Operationoperator: 30
operands: 13
10Operationoperator: 14
operands: 15
11Literal
12ExprTuple16
13ExprTuple49, 17
14Literal
15ExprTuple18, 48
16Lambdaparameter: 54
body: 19
17Operationoperator: 20
operands: 21
18Operationoperator: 22
operand: 49
19Conditionalvalue: 24
condition: 25
20Literal
21ExprTuple26, 27
22Literal
23ExprTuple49
24Operationoperator: 28
operands: 29
25Operationoperator: 30
operands: 31
26Literal
27Literal
28Literal
29ExprTuple32, 33, 34
30Literal
31ExprTuple54, 35
32ExprTuple36
33ExprTuple37
34ExprTuple38
35Operationoperator: 39
operands: 40
36Operationoperator: 41
operands: 42
37Operationoperator: 43
operands: 44
38Operationoperator: 45
operands: 46
39Literal
40ExprTuple47, 48
41Literal
42NamedExprsstate: 49
43Literal
44NamedExprsbasis: 50
45Literal
46NamedExprsstate: 51
47Literal
48Literal
49Variable
50Literal
51Operationoperator: 52
operand: 54
52Literal
53ExprTuple54
54Variable