-
Notifications
You must be signed in to change notification settings - Fork 179
Proposal: Math Lib is missing some APIs. #413
Comments
I think these don't have to be intrinsic, right? function NaN() : Double {
return 0.0 / 0.0;
}
function IsNaN(d : Double) : Bool {
return d != d;
}
function Infinity() : Double {
return 1.0 / 0.0;
}
function IsInfinity(d : Double) : Bool {
// Or remove this function in favor of directly using "d == Infinity()".
return d == Infinity();
}
function IsNegativeInfinity(d : Double) : Bool {
// Or remove this function in favor of directly using "d == -Infinity()".
return d == -Infinity();
} |
As a clarification, which namespace would you propose for these new callables? It seems like Microsoft.Quantum.Math may be the best bet, since these callables concern classical math operations similar to existing functions and operations in that namespace. |
@SamarSha, looks like you are right ;-) |
@cgranade, I agree, Microsoft.Quantum.Math looks a good place. |
I think you could define negative infinity as |
@SamarSha, I like the ideas in both your of posts! |
I'd suggest going with namespace Microsoft.Quantum.Math {
function IsInfinite(d : Double) : Bool {
return d == 1.0 / 0.0 or d == -1.0 / 0.0;
}
function IsFinite(d : Double) : Bool {
return not IsInfinite(d) and not IsNaN(d);
}
}
namespace Microsoft.Quantum.Diagnostics {
function FiniteFact(d : Double, message : String) : Unit {
Fact(IsFinite(d), message);
}
} Positive and negative infinities can still be discriminated by checking |
@kuzminrobin: The API review for March is coming up in a few days, it would be good to get this in to that review cycle. Would you be willing to update your proposal to include the namespace, and the feedback from me and @samarsh, so that we can get it added to the discussion? Thank you! |
Based on the feedback/discussion, the updated version of the proposal is below: namespace Microsoft.Quantum.Math {
function NaN() : Double {
return 0.0 / 0.0;
}
function IsNaN(d : Double) : Bool {
return d != d;
}
function IsInfinite(d : Double) : Bool {
return d == 1.0 / 0.0 or d == -1.0 / 0.0;
// Positive and negative infinities can still be
// discriminated by checking `d > 0.0` and `d < 0.0`.
}
function IsFinite(d : Double) : Bool {
return not IsInfinite(d) and not IsNaN(d);
}
}
namespace Microsoft.Quantum.Diagnostics {
function FiniteFact(d : Double, message : String) : Unit {
Fact(IsFinite(d), message);
}
} |
Based on #426, the proposal has been approved as written, thanks for driving this!
|
Wow! Cool! |
@kuzminrobin: Similarly to #418, I'm happy either if you want to take this on, or if you'd prefer for me to. Either way, I've marked it in the March milestone to indicate that we'll try to take this on for the March release. As far as implementation, the main work here will be writing documentation comments and unit tests, since the implementation is already fully specified in the proposal itself. |
@bettinaheim @swernli: In terms of dependency ordering, should this one live in libraries or the runtime repo (i.e.: QSharpFoundation)? |
This should go in the runtime repo, in QSharpFoundation. One thing I'm confused on: function IsNaN(d : Double) : Bool {
return d != d;
} If I pass 4.0 to function IsNaN(d : Double) : Bool {
return d != NaN();
} |
No, because
Do you mean |
Whoops, never mind. I inverted the Boolean in my head. If a double is NOT equal to itself then it is NaN. I get it now. |
That's what I was thinking, but wasn't sure... I'll go on and add these there, then. Thanks!
It will never sit well with me that IEEE 754 fails to be reflexive... I trip up all the time on |
@cgranade, I can get back to this later. Feel free to go ahead and make the change if you have time and desire. |
@kuzminrobin: Since the March milestone will be closing in not too long, I'll go on and take care of this one, then. Want to make sure we don't miss the release window. |
|
(This is the original proposal text. See the updated version of this proposal below)
I propose (to the Q# API Design Review Board) to add to the Q# API the following missing calls to support the Math library.
Currently they are needed to implement the
Log()
math function.More details:
Discussion
Possible Implementation
The text was updated successfully, but these errors were encountered: