GY-63_MS5611/libraries/Interval/README.md

141 lines
4.1 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/Interval/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-20 10:47:55 -05:00
[![Arduino-lint](https://github.com/RobTillaart/Interval/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Interval/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/Interval/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Interval/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Interval/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Interval.svg?maxAge=3600)](https://github.com/RobTillaart/Interval/releases)
# Interval
2021-12-20 10:47:55 -05:00
Arduino library for the Interval data type. **Experimental**
2021-01-29 06:31:58 -05:00
## 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:**
2021-12-20 10:47:55 -05:00
The data type Interval was created to do some experiments.
It was inspired by the **frink** language which has an interval data type.
2021-01-29 06:31:58 -05:00
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.
```cpp
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 <= **
2021-05-28 07:35:27 -04:00
2021-01-29 06:31:58 -05:00
### 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
2021-12-20 10:47:55 -05:00
## Future
- play and extend the library.
- check all to be investigated above.
- clean up the documentation.