microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dbwy/random_seed

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/algorithms/HypercubeLookup/src/Data.qs

81lines · modecode

1// Hypercube vertex data
2
3import ClassicalSearch.GetIndexBelowThresholdClassically;
4import Std.Diagnostics.*;
5import Std.Math.BitSizeI;
6
7/// # Summary
8/// Selected hypercube vertices represented as coordinate bit strings.
9function HypercubeVertices() : Bool[][] {
10 [
11 [false, false, false, false, false, false], // 0: d = 6
12 [false, true, false, false, false, false], // 1: d = 5
13 [false, true, true, true, false, false], // 2: d = 3
14 [true, false, true, false, false, false], // 3: d = 4
15 [true, true, false, true, false, false], // 4: d = 3
16 [false, false, true, true, false, false], // 5: d = 4
17 [true, false, true, true, true, false], // 6: d = 2
18 [true, true, false, false, false, true], // 7: d = 3
19 ]
20}
21
22/// # Summary
23/// The query vertex represented as a coordinate bit string.
24/// We are searching for a selected vertex closest to this one.
25function QueryVertex() : Bool[] {
26 [true, true, true, true, true, true]
27}
28
29/// # Summary
30/// The number of dimensions of the hypercube.
31/// Also verifies the assumptions about the data.
32function HypercubeDimentions() : Int {
33 Length(QueryVertex())
34}
35
36/// # Summary
37/// The number of selected vertices of the hypercube.
38function TableLength() : Int {
39 Length(HypercubeVertices())
40}
41
42/// # Summary
43/// We are finding a vertex under this threshold.
44/// Only one vertex should satisfy this condition.
45function DistanceThreshold() : Int {
46 3
47}
48
49/// # Summary
50/// The maximum possible distance in the hypercube.
51function MaxDistance() : Int {
52 HypercubeDimentions()
53}
54
55/// # Summary
56/// The number of bits needed to represent the maximum distance.
57function MaxDistanceBits() : Int {
58 BitSizeI(MaxDistance())
59}
60
61/// # Summary
62/// The number of bits needed to address all selected vertices.
63/// Also veifies all assumptions about the table data.
64function TableAddressBits() : Int {
65 let dimensions = Length(QueryVertex());
66 for vertex in HypercubeVertices() {
67 Fact(Length(vertex) == dimensions, "All vertices must have the same number of dimensions as the query vertex.");
68 }
69
70 let tableSize = TableLength();
71 Fact((tableSize &&& (tableSize - 1)) == 0, "Table length needs to be a power of two. Otherwise, respectExcessiveAddress option must be true.");
72
73 let index = GetIndexBelowThresholdClassically(
74 HypercubeVertices(),
75 QueryVertex(),
76 DistanceThreshold()
77 );
78 Fact(index >= 0 and index < TableLength(), "One table index must satisfy the distance threshold condition.");
79
80 BitSizeI(TableLength() - 1)
81}
82