Is there a difference between the PositiveReals set and the NonNegativeReals set? - pyomo

I am wondering if there are any differences between the predefined PositiveReals and NonNegativeReals sets.
I have read the documentation on predefined sets but I can't find the difference explicitly stated.

Non-negative reals include 0.
Positive reals do not include 0.

Related

(wx)Maxima: turn off scientific notation

Currently, something like 0.9*120 returns 1.08+2 whereas I'd like to set the default for all numbers to be returned in non-scientific notation.
I found fix in the documentation; however, this solution is only appropriate for integer values.
I found some old posts on the Maxima mailing list on source forge, but the suggestion is to use printf with ~f -- is there no way to make this the default format? or does one really have to convert every value, individually?
In my case, the defaults for the floating-point precision fpprec and the floating-point print precision fpprintprec had been changed by our system administrator, and I wasn't aware. Changing their values back to the default resolved the issue.
The defaults, according to the documentation, at the time of writing, are:
fpprec:16;
fpprintprec:0
As the documentation for fpprintprec explains:
For ordinary floating point numbers, when fpprintprec has a value between 2 and 16 (inclusive), the number of digits printed is equal to fpprintprec. Otherwise, fpprintprec is 0, or greater than 16, and the number of digits printed is 16.

designing a large compressible binary float in Fortran

I would like to design a "fill" value for 4 and 8 byte float variables in a netcdf file to represent a special case of missing data. There is already a constant NF_FILL_FLOAT and my understanding about its design is that besides being a large, strange value it has a very compressible bit pattern. I believe it is different than huge(x). I already use NF_FILL_FLOAT to fill missing values -- my value has to be distinguishable. How do I go about this? What are the considerations for compression? Thanks.
What about if you take NF_FILL_FLOAT and divide it by 2**n, where n is an integer >=0 ? This would give you "n" individual "fill values" and essentially the division is simply shifting the bits by n, so should still be compressible.
(Of course, if you write out to a netcdf, then external software is only designed to recognise one value of MISSING, so your fill values would not be recognised).

Sorting a list containing NaNs

If I have a list of floating point numbers containing: Infinity, -Infinity, Other random decimal number and one NaN. Where should the NaN be after the list has been sorted?? I'm using bubble sort if that helps
In order to sort you need a consistent order, which means, for example, making an ordering rule for NaN.
Fortunately, the work has already been done in Java. java.lang.Double is Comparable, and its compareTo uses extended rules including "Double.NaN is considered by this method to be equal to itself and greater than all other double values (including Double.POSITIVE_INFINITY)."
It also has a compare method that compares two double primitives using those extended rules, rather than the <= etc. rules.
If you are programming in Java you can use this directly in your sort. If you are using float rather than double, see the corresponding method in java.lang.Float. If you are programming in another language, you can still read and copy the rules from Java, and use them in your comparison function.
If you use this in your sort you should expect NaN to be at the very end of the sorted list, after all finite values and positive infinity.
You cannot sort a list of floating-point values including NaN using <= as comparison because <= is not an order on floating-point values including NaN: it is not reflexive (NaN <= NaN would have to hold for <= to be reflexive. It doesn't).
You are breaking the pre-requisites of the sorting algorithm. Anything can happen.
The NaN would be put at the beginning or the end of the sorted array depending on the implementation of Bubble Sort in question.
It depends entirely on how you define your ordering criterion.

Issue with std::numeric_limits<T>::min() with float/double values

While writing some code to ensure user input is valid I came across an issue with std::numeric_limits<T>::min(); where T is a floating point type i.e double/float etc.
Using -std::numeric_limits<double>::max(); allows me to get the real minimum value but you would expect std::numeric_limits<double>::min(); to return that.
Why does std::numeric_limits<double>::min(); not return the smallest possible value of these types and instead force us to use std::numeric_limits::lowest or -std::numeric_limits<double>::max();?
Yes, using -max() will give lowest value.
In C++11 there is also std::numeric_limits::lowest that is consistent for reals and ints.
http://en.cppreference.com/w/cpp/types/numeric_limits/lowest
See also How to workaround the inconsistent definition of numeric_limits<T>::min()?
Why is this?
This is because std::numeric_limits<>::min() returns implementation defined FLT_MIN, DBL_MIN or INT_MIN. In this regard behavior of this method is consistent. But the return value ofstd::numeric_limits<double>::min(): DBL_MIN has slightly different meaning than INT_MIN. This is the smallest value that double can represent. There might be value greater than 0 but double can't represent it.
why does using min() not do the same thing in this instance?
The rationale behind this is that you can query <limits> for this value to check for this possible underflow specific to floating point arithmetic.
You can use
std::numeric_limits<double>::lowest()
to query for a lowest negative value.

Why numeric_limits<int>::min() is differently defined?

To retrieve the smallest value i have to use numeric_limits<int>::min()
I suppose the smallest int is -2147483648, and tests on my machine showed this result.
But some C++ references like Open Group Base Specifications and
cplusplus.com define it with the value -2147483647.
I ask this question because in my implementation of the negaMax Framework (Game Tree Search)
the value minimal integer * (-1) has to be well defined.
Yes, with minimal int = (numeric_limits::min() + 2) i am on the safe side in any case,
thus my question is more theoretically but i think nevertheless quite interesting.
If a value is represented as sign-and-magnitude instead of two's complement, the sign bit being one with all other bits as zero is equivalent to -0. In sign-and-magnitude the maximum positive integer and negative integer are the same magnitude. Two's complement is able to represent one more negative value because it doesn't have the same symmetry.
The value of numeric_limits<int>::min() is defined by implementation. That's why it could be different. You shouldn't stick to any concrete minimal value.
On cplusplus.com you forgot to read the qualifier
min. magnitude*
This is not necessarily the actual value of the constant in any particular compiler or system, it may be equal or greater in magnitude than this.
From the cplusplus.com link you posted (emphasis mine):
The following panel shows the different constants and their guaranteed minimal magnitudes (positive numbers may be greater in value, and negative numbers may be less in value). Any particular compiler implementation may define integral types with greater magnitudes than those shown here
Numeric limits are always system and compiler defined, try running with a 64bit compiler and system, you may see totally different numbers.
c++ uses two-s compliment for signed integers. Thus the smallest signed integer is defined by 100..00 (usually 32 bit).
Simply shifting 1<<(sizeof(int)*8-1) should give you the smallest signed integer.
Obviously for unsigned integers, the smallest is 0.
edit: you can read more here
edit2: apparently C++ doesn't necessarily use two-s compliment, my mistake