-
Notifications
You must be signed in to change notification settings - Fork 8
/
aaa.html
56 lines (47 loc) · 1.9 KB
/
aaa.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<head>
<title>A simple game in one file</title>
<script src="https://unpkg.com/quantum-tensors@0.4.15/dist/quantum-tensors.min.js"></script>
</head>
<body>
<h1>A simple game in one file</h1>
<p id="display-state"></p>
<p id="display-entangelment"></p>
<button id="button" onClick="onButtonClick()">Regenerate state</button>
<button id="ans-entangled" onClick="answer(true)">Entangled!</button>
<button id="ans-separable" onClick="answer(false)">Not entangled!</button>
<script>
// importing parts we need from Quantum Tensors
const { Cx, Vector, Entanglement, Dimension } = QuantumTensors;
let state = Vector.fromSparseCoordNames([
['00', Cx(0.5)],
['01', Cx(0.5)],
['10', Cx(-0.5)],
['11', Cx(0.5)]], Dimension.qubits(2));
const displayState = document.getElementById('display-state');
const displayEntanglement = document.getElementById('display-entangelment');
const updateViewer = () => {
displayState.innerHTML = state.toKetString();
displayEntanglement.innerHTML = Entanglement.renyi2(state, [0]).toFixed(3);
};
updateViewer();
const onButtonClick = () => {
console.log("Button clicked!");
const r = Math.random();
if (r < 0.5) {
const qubit1 = Vector.random(Dimension.qubits(1));
const qubit2 = Vector.random(Dimension.qubits(1));
state = qubit1.outer(qubit2);
} else {
state = Vector.random(Dimension.qubits(2));
}
updateViewer();
};
const answer = (entangled) => {
if (Entanglement.renyi2(state, [0]).toFixed(3) > 0.001) {
alert("You are entangled!");
} else {
alert("You are not entangled!");
}
}
</script>
</body>