This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 923
/
ResourceCounting.qs
51 lines (49 loc) · 1.88 KB
/
ResourceCounting.qs
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Numerics.Samples {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Arrays;
/// # Summary
/// Evaluates the polynomial given by `coefficients` at the
/// evaluation points provided.
///
/// # Input
/// ## coefficients
/// Polynomial coefficients, see Evaluate[Even/Odd/_]PolynomialFxP
/// ## evaluationPoints
/// Points at which to evaluate the polynomial
/// ## numBits
/// Number of bits to use to represent each fixed-point number
/// ## pointPos
/// Point position to use for the fixed-point representation
/// ## odd
/// If True, evaluates an odd polynomial (see EvaluateOddPolynomialFxP)
/// ## even
/// If True, evaluates an even polynomial (see EvaluateEvenPolynomialFxP)
operation EvaluatePolynomial(coefficients : Double[], evaluationPoints : Double[],
numBits : Int, pointPos : Int, odd : Bool, even : Bool)
: Double[]
{
mutable results = [0.0, size = Length(evaluationPoints)];
for i in IndexRange(evaluationPoints) {
let point = evaluationPoints[i];
use (xQubits, yQubits) = (Qubit[numBits], Qubit[numBits]);
let x = FixedPoint(pointPos, xQubits);
let y = FixedPoint(pointPos, yQubits);
PrepareFxP(point, x);
if (odd) {
EvaluateOddPolynomialFxP(coefficients, x, y);
}
elif (even) {
EvaluateEvenPolynomialFxP(coefficients, x, y);
}
else {
EvaluatePolynomialFxP(coefficients, x, y);
}
set results w/= i <- MeasureFxP(y);
ResetAll(xQubits + yQubits);
}
return results;
}
}