Skip to content

Commit

Permalink
more doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Apr 29, 2024
1 parent f0b2607 commit a233ce2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ all: html pdf
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html
-cp _build/latex/$(PDFFILE) _build/html/.
@echo
-cd _build && ln -s html uncertainties_doc && zip -pur uncertainties_doc.zip uncertainties_doc/* && mv uncertainties_doc.zip html
-cd _build && ln -s html uncertainties_doc && zip -pur uncertainties_doc.zip uncertainties_doc/* && mv uncertainties_doc.zip html && rm -f uncertainties_doc
@echo "Build finished. The HTML pages are in _build/html."

help:
Expand Down
2 changes: 1 addition & 1 deletion doc/tech_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ since :data:`x` and :data:`y` are independent random variables that
*almost* always give a different value (put differently,
:data:`x`-:data:`y` is not equal to 0, as it can take many different
values). Note that this is different
from the result of ``z = 3.14; t = 3.14; print z == t``, because
from the result of ``z = 3.14; t = 3.14; print(z == t)``, because
:data:`x` and :data:`y` are *random variables*, not pure numbers.

Similarly,
Expand Down
75 changes: 38 additions & 37 deletions doc/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ The functions in the :mod:`uncertainties.umath` module include:
Comparison operators
====================

Comparison operators ('==', '!=', '>', '<', '>=', and '<=') for for values with
Comparison operators ('==', '!=', '>', '<', '>=', and '<=') for values with
uncertainties are somewhat complicated, and need special atention. As we
hinted at above, and will explore in more detai below and in the
:ref:`Technical Guide <comparison_operators>`, this relates to the correlation
Expand All @@ -203,61 +203,62 @@ True
False

In order for the resuls of two calculations with uncertainties to be considered
equal, but the nomimal value *and* the uncertainty must have the same value.
equal, the nomimal value *and* the uncertainty must have the same value.


Comparisons of magnitude
------------------------------------

>>> print(x)
0.200+/-0.010
>>> y = x + 0.0001
>>> y
0.2001+/-0.01
>>> y > x
True
>>> y > 0
The concept of comparing the magnitude of values with uncertainties is a bit
complicated. That is, a Variable with a value of 25 +/- 10 might be greater
than a Varitable with a value of 24 +/- 8 most of the time, but *sometimes* it
might be less than it. The :mod:`uncertainties` package takes the simple
approach of comparing. That is

>>> a = ufloat(25, 10)
>>> b = ufloat(24, 8)
>>> a > b
True

One important concept to keep in mind is that :func:`ufloat` creates a
random variable, so that two numbers with the same nominal value and
standard deviation are generally different:
Note that cobining this comparison and the above discussion of `==` and `!=`
can lead to a result that maybe somewhat surpring:

>>> y = ufloat(1, 0.1)
>>> z = ufloat(1, 0.1)
>>> print(y)
1.00+/-0.10
>>> print(z)
1.00+/-0.10
>>> y == y
True
>>> y == z
False

In physical terms, two rods of the same nominal length and uncertainty
on their length are generally of different sizes: :data:`y` is different
from :data:`z`.
>>> a = ufloat(25, 10)
>>> b = ufloat(25, 8)
>>> a >= b
False
>>> a > b
False
>>> a == b
False
>>> a.nominal_value >= b.nominal_value
True

That is, since `a` is neither greeater than `b` (nomal value only) nor equal to
`b`, it cannot be greater than or equal to `b`.


.. index::
pair: testing (scalar); NaN


NaNs testing
====================
Handling NaNs and infinities
===============================

Uncertainty Variables that contain NaN values can appear in a number with
uncertainty. Care must be taken with such values, as values like NaN±1, 1±NaN
and NaN±NaN are by definition *not* NaN, which is a float.
NaN values can appear in either the nominal value or uncertainty of a
Variable. As is always the case, care must be exercised when handling NaN
values.

Testing whether a number with uncertainty has a **NaN nominal value** can
be done with the provided function ``uncertainties.umath.isnan()``,
which generalizes the standard ``math.isnan()``.
While :func:`math.isnan` and :func:`numpy.isnan` will raise `TypeError`
exceptions for uncertainties Variables (because an uncertainties Variable is
not a float), the function :func:`umath.isnan` will return whether the nominal
value of a Variable is NaN. Similarly, :func:`umath.isinf` will return whether
the nominal value of a Variable is infinite.

Checking whether the *uncertainty* of ``x`` is NaN can be done directly
with the standard function: ``math.isnan(x.std_dev)`` (or equivalently
``math.isnan(x.s)``).
To check whether the uncertainty is NaN or Inf, use one of :func:`math.isnan`,
:func:`math.isinf`, :func:`nupmy.isnan`, or , :func:`nupmy.isinf` on the
``std_dev`` attribute.


.. index:: arrays; simple use, matrices; simple use
Expand Down

0 comments on commit a233ce2

Please sign in to comment.