GY-63_MS5611/libraries/Interval
2022-11-14 19:10:33 +01:00
..
.github add funding.yml 2022-08-03 21:56:07 +02:00
examples/interval_demo 0.1.2 Interval 2021-12-20 16:47:55 +01:00
test 0.1.2 Interval 2021-12-20 16:47:55 +01:00
.arduino-ci.yml 0.1.3 Interval 2022-11-14 19:10:33 +01:00
CHANGELOG.md 0.1.3 Interval 2022-11-14 19:10:33 +01:00
Interval.cpp 0.1.3 Interval 2022-11-14 19:10:33 +01:00
Interval.h 0.1.3 Interval 2022-11-14 19:10:33 +01:00
keywords.txt 0.1.2 Interval 2021-12-20 16:47:55 +01:00
library.json 0.1.3 Interval 2022-11-14 19:10:33 +01:00
library.properties 0.1.3 Interval 2022-11-14 19:10:33 +01:00
LICENSE 0.1.2 Interval 2021-12-20 16:47:55 +01:00
README.md 0.1.2 Interval 2021-12-20 16:47:55 +01:00

Arduino CI Arduino-lint JSON check License: MIT GitHub release

Interval

Arduino library for the Interval data type. Experimental

Description

This experimental library provides basic math when you do not know a quantity. The only thing you do know is the value is in a certain interval. After doing some math you want to know the interval of possible outcomes.

An interval exist of a pair of floats, low and high, the borders of the interval.

footnote: The data type Interval was created to do some experiments. It was inspired by the frink language which has an interval data type. Frink itself is not investigated, so semantics are not necessary similar.

Interface

The Interval class implements the public interface of Printable. This allows you to print an Interval in human readable form.

    Interval x(3, 4);
    x.setDecimals(2);
    Serial.println(x); // will print [3.00, 4.00]

Constructors

  • Interval() zero = interval [0, 0]
  • Interval(float lo, float hi) interval [lo, hi]
  • Interval(float f) interval [f, f]

Basic functions

The basic functions are used to get and set some core attributes.

  • setDecimals() set nr of decimals for printing.
  • value() is the middle of the interval (as we do not know distribution)
  • range() = high() - low()
  • high() idem
  • low() idem
  • relAccuracy() = range() / value()
  • setRange(float r) adjust range around value() =- r/2

Math Operators

Math operators

  • addition + +=
  • subtraction - -=
  • multiplication * *=
  • quotient / /=

Functions

Functions are not implemented yet as these need to be investigated. For a monotonous function it is relative easy

Interval v = F( [a, b] );         ==> [ F(a), F(b)]
e.g.
Interval f = exp( [a, b]);        ==> [exp(a), exp(b)]
Interval g = log( [a, b]);        ==> [log(a), log(b)]    a > 0!!

The math for non monotonous functions is more complex as one cannot use the function values as above.

Interval p = sin( [0, PI] );      ==> [0, 1]
Interval q = sin( [0, -PI] );     ==> [-1, 0]
Interval r = sin( [0, 10 * PI] ); ==> [-1, 1]

Interval s = sqr( [-5, -3] ) ;    ==> [9, 25]
Interval t = sqr( [-5,  3] ) ;    ==> [0, 25]

  • change range while keeping value.

Comparison operators

To be investigated. The semantics make at least a difference between when an interval is Certainly Less Equal or Probably Less or Equal. The Certainly group will be boolean math as we know it. The Probably group will be more like fuzzy logic so a float between 0..100%.

  • **bool == **
  • **bool != **
  • **bool > **
  • **bool >= **
  • **bool < **
  • **bool <= **

Set operators

To be investigated include:

  • If you have two or more intervals, what is the 'super interval' that includes all?
  • How to subtract elements of an interval from another Interval?
    This is different than the subtraction above,
    think of it as " I know the number I look for is in [1, 4] but it is not in [3, 5]
    so it is in [1,3]

Other

  • a known problem is difference between border inclusive [ ] and
    border exclusive < >. How to deal with that?
  • 1/[-1, 1] ==> ?? singularity for 0?
  • infinity as border? In math we have [0, ->> for all positive floats.

Operation

See example

Future

  • play and extend the library.
  • check all to be investigated above.
  • clean up the documentation.