From 0890fb1a7213b51c73497a36af324584025a9edd Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Fri, 25 Oct 2019 17:05:27 -0700 Subject: [PATCH 1/3] Clarify the restriction on the number of bits for IntAsBoolArray This should fix #166 by providing a more specific error message. --- Standard/src/Convert/Convert.qs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Standard/src/Convert/Convert.qs b/Standard/src/Convert/Convert.qs index b69b24bd51d..4237071c3c7 100644 --- a/Standard/src/Convert/Convert.qs +++ b/Standard/src/Convert/Convert.qs @@ -76,8 +76,10 @@ namespace Microsoft.Quantum.Convert { /// An array of boolean values representing `number`. /// /// # Remarks + /// The input `bits` must be between 1 and 63. /// The input `number` must be at most $2^{\texttt{bits}} - 1$. function IntAsBoolArray(number : Int, bits : Int) : Bool[] { + EqualityFactB(bits >= 1 and bits <= 63, true, $"`bits` must be between 1 and 63 {2^bits}"); EqualityFactB(number >= 0 and number < 2 ^ bits, true, $"`number` must be between 0 and 2^`bits` - 1"); mutable outputBits = new Bool[bits]; mutable tempInt = number; From 8adc3bee1b0e4e7677d53b57ec8a79163b46e45f Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Tue, 5 Nov 2019 08:42:40 -0800 Subject: [PATCH 2/3] Update Standard/src/Convert/Convert.qs Co-Authored-By: Chris Granade --- Standard/src/Convert/Convert.qs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Standard/src/Convert/Convert.qs b/Standard/src/Convert/Convert.qs index 4237071c3c7..af1a809b6ea 100644 --- a/Standard/src/Convert/Convert.qs +++ b/Standard/src/Convert/Convert.qs @@ -79,7 +79,7 @@ namespace Microsoft.Quantum.Convert { /// The input `bits` must be between 1 and 63. /// The input `number` must be at most $2^{\texttt{bits}} - 1$. function IntAsBoolArray(number : Int, bits : Int) : Bool[] { - EqualityFactB(bits >= 1 and bits <= 63, true, $"`bits` must be between 1 and 63 {2^bits}"); + Fact(bits >= 1 and bits <= 63, $"`bits` must be between 1 and 63 {2^bits}"); EqualityFactB(number >= 0 and number < 2 ^ bits, true, $"`number` must be between 0 and 2^`bits` - 1"); mutable outputBits = new Bool[bits]; mutable tempInt = number; From 073b409aaffd4a68c899cd20b3add8acbc7e4fe8 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Fri, 22 Nov 2019 17:11:48 -0800 Subject: [PATCH 3/3] Allow to have bits = 0 Looks like our tests assume that number = 0 with bits = 0 is a valid scenario; updating the change to account for that --- Standard/src/Convert/Convert.qs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Standard/src/Convert/Convert.qs b/Standard/src/Convert/Convert.qs index af1a809b6ea..85a89b88367 100644 --- a/Standard/src/Convert/Convert.qs +++ b/Standard/src/Convert/Convert.qs @@ -76,10 +76,10 @@ namespace Microsoft.Quantum.Convert { /// An array of boolean values representing `number`. /// /// # Remarks - /// The input `bits` must be between 1 and 63. - /// The input `number` must be at most $2^{\texttt{bits}} - 1$. + /// The input `bits` must be between 0 and 63. + /// The input `number` must be between 0 and $2^{\texttt{bits}} - 1$. function IntAsBoolArray(number : Int, bits : Int) : Bool[] { - Fact(bits >= 1 and bits <= 63, $"`bits` must be between 1 and 63 {2^bits}"); + Fact(bits >= 0 and bits <= 63, $"`bits` must be between 0 and 63 {2^bits}"); EqualityFactB(number >= 0 and number < 2 ^ bits, true, $"`number` must be between 0 and 2^`bits` - 1"); mutable outputBits = new Bool[bits]; mutable tempInt = number;