errors icon indicating copy to clipboard operation
errors copied to clipboard

exponential format not used if value is zero

Open alusiani opened this issue 5 years ago • 4 comments

When the value is zero and the uncertainty a very small or very large number, then the exponential format is not used, but it ought to be in my opinion. This is an example

> library(errors)
> x=0
> errors(x)=1.234e10; print(x,digits=4)
0(12340000000)

A possible way to get an exponential formatting could be to get the exponent from the uncertainty when the values is zero, i.e. in print.R changing from

  exponent <- get_exponent(x)

to

  e <- signif(errors(x), digits)
  e_expon = get_exponent(e)
  exponent <- ifelse(as.numeric(x)==0, e_expon+1, get_exponent(x))

Cheers,

alusiani avatar Jan 02 '21 18:01 alusiani

What do you think that the output should be? And what's special about zero? I mean, why with zero and not with every other number when the uncertainty is bigger than the value?

Enchufa2 avatar Jan 02 '21 20:01 Enchufa2

What do you think that the output should be? And what's special about zero? I mean, why with zero and not with every other number when the uncertainty is bigger than the value?

I think that the output should be 0.000(1234)e-9 rather than 0(12340000000), more similar to what happens when the value is not zero, when the exponential format is used for expressing values/uncertainties >= 1e6.

Regarding values !=0 with uncertainties larger than the values, I see that with the change I suggest here plus the change for getting the decimal point, I get a reasonable formatting:

> x=1.234
> errors(x) = 70.689
> print(x, digits=4)
1.23(70.69)

alusiani avatar Jan 02 '21 20:01 alusiani

I think that the output should be 0.000(1234)e-9 rather than 0(12340000000), more similar to what happens when the value is not zero, when the exponential format is used for expressing values/uncertainties >= 1e6.

I think you mean 0.000(1234)e10, right? The problem is not whether the value is zero or not, the problem is whether the uncertainty is larger than the value. With non-zero values, you get, e.g.,

> print(set_errors(1e6, 23e10), digits=2)
1(230000)e6

which should be... 0.0001(23000)e11 maybe? So the general case is much more complicated (and I don't see much gain in it, at least in terms of digits required to express the quantities). Also, it could be confusing for the user, because basically we would be inadvertently changing the rules for scientific notation: if uncertainty < value, then it depends on the value; if uncertainty > value, it depends on the uncertainty.

Regarding values !=0 with uncertainties larger than the values, I see that with the change I suggest here plus the change for getting the decimal point, I get a reasonable formatting:

> x=1.234
> errors(x) = 70.689
> print(x, digits=4)
1.23(70.69)

I'm interested here in the formatting with the current default notation, which will continue, as I mentioned in #47, even if we implement your proposal as an optional notation. So please don't merge the issues. Besides, this particular example is just fine now:

> print(set_errors(1.234, 70.689), digits=4)
1.23(7069)

Enchufa2 avatar Jan 04 '21 13:01 Enchufa2

I think that the output should be 0.000(1234)e-9 rather than 0(12340000000), more similar to what happens when the value is not zero, when the exponential format is used for expressing values/uncertainties >= 1e6.

I think you mean 0.000(1234)e10, right? The problem is not whether the value is zero or not, the problem is whether the uncertainty is larger than the value. With non-zero values, you get, e.g.,

I did mean 0.000(1234)e-9, with e10 I would prefer 0.000(1.234)e10, therefore I set the default exponent based on the uncertainty to get a zero on the left of the decimal point.

> print(set_errors(1e6, 23e10), digits=2)
1(230000)e6

which should be... 0.0001(23000)e11 maybe? So the general case is much more complicated (and I don't see much gain in it, at least in terms of digits required to express the quantities). Also, it could be confusing for the user, because basically we would be inadvertently changing the rules for scientific notation: if uncertainty < value, then it depends on the value; if uncertainty > value, it depends on the uncertainty. ...

With the modification I propose:

> print(set_errors(1e6, 23e10), digits=2)
1(230000)e6

In my opinion, a value of zero is not just like a value smaller than its uncertainty, it is rather a value that does not set a scale, and the best scale to minimize the formatted string can be conveniently set by using the scale of the uncertainty.

Let me show an example of what happens with the present code:

> print(set_errors(1e12, 0.1e12), digits=2)
1.00(10)e12
> print(set_errors(0e10, 0.1e12), digits=2)
0(100000000000)

and what happens with the modification I propose

> print(set_errors(1e12, 0.1e12), digits=2)
1.00(10)e12
> print(set_errors(0e10, 0.1e12), digits=2)
0.00(10)e12

Having a value=0 permits formatting both as 0(100000000000) and as 0.00(10)e12 and I prefer the second option.

alusiani avatar Jan 05 '21 23:01 alusiani