mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.7 statHelpers
This commit is contained in:
parent
17f6553ac2
commit
da98215f89
@ -6,7 +6,7 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: arduino/arduino-lint-action@v1
|
- uses: arduino/arduino-lint-action@v1
|
||||||
with:
|
with:
|
||||||
library-manager: update
|
library-manager: update
|
||||||
|
@ -8,7 +8,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: 2.6
|
ruby-version: 2.6
|
||||||
|
@ -10,7 +10,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: json-syntax-check
|
- name: json-syntax-check
|
||||||
uses: limitusus/json-syntax-check@v1
|
uses: limitusus/json-syntax-check@v1
|
||||||
with:
|
with:
|
||||||
|
@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.7] - 2023-03-15
|
||||||
|
- update readme.md
|
||||||
|
- update GitHub actions
|
||||||
|
- update license 2023
|
||||||
|
- minor edits
|
||||||
|
|
||||||
|
|
||||||
## [0.1.6] - 2022-11-25
|
## [0.1.6] - 2022-11-25
|
||||||
- Add RP2040 support to build-CI.
|
- Add RP2040 support to build-CI.
|
||||||
- Add CHANGELOG.md
|
- Add CHANGELOG.md
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2010-2022 Rob Tillaart
|
Copyright (c) 2010-2023 Rob Tillaart
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -14,11 +14,20 @@ Arduino library with a number of statistic helper functions.
|
|||||||
## Description
|
## Description
|
||||||
|
|
||||||
This library contains functions that have the goal to help with
|
This library contains functions that have the goal to help with
|
||||||
some basic statistical calculations.
|
basic statistical calculations like permutations, combinations,
|
||||||
|
and factorials.
|
||||||
|
|
||||||
|
It includes an experimental section for large numbers.
|
||||||
|
Note that these are very computation (time) intensive so not suited for real time math :)
|
||||||
|
|
||||||
To print very large numbers - https://github.com/RobTillaart/PrintHelpers
|
To print very large numbers - https://github.com/RobTillaart/PrintHelpers
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "statHelpers.h"
|
||||||
|
```
|
||||||
|
|
||||||
### Permutation
|
### Permutation
|
||||||
|
|
||||||
@ -56,6 +65,8 @@ but accuracy is less than the **dfactorial()**, see example.
|
|||||||
|
|
||||||
### SemiFactorial
|
### SemiFactorial
|
||||||
|
|
||||||
|
SemiFactorials are like factorials but skipping every other.
|
||||||
|
|
||||||
- **uint32_t semiFactorial(n)** exact up to 20!!
|
- **uint32_t semiFactorial(n)** exact up to 20!!
|
||||||
- **uint64_t semiFactorial64(n)** exact up to 33!! (Print 64 bit integers with my printHelpers)
|
- **uint64_t semiFactorial64(n)** exact up to 33!! (Print 64 bit integers with my printHelpers)
|
||||||
- **double dSemiFactorial(n)** not exact up to 56!! (4 byte) or 300!! (8 byte)
|
- **double dSemiFactorial(n)** not exact up to 56!! (4 byte) or 300!! (8 byte)
|
||||||
@ -64,6 +75,7 @@ SemiFactorial are defined for
|
|||||||
- **odd** values: n x (n-2) x (n-4) ... x 1
|
- **odd** values: n x (n-2) x (n-4) ... x 1
|
||||||
- **even** values: n x (n-2) x (n-4) ... x 2
|
- **even** values: n x (n-2) x (n-4) ... x 2
|
||||||
|
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
```n! = n!! x (n-1)!!``` this formula allows to calculate the value of n! indirectly
|
```n! = n!! x (n-1)!!``` this formula allows to calculate the value of n! indirectly
|
||||||
|
|
||||||
@ -94,13 +106,13 @@ Uses Pascal's triangle.
|
|||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
- **perm1** is a sketch in the examples that shows a recursive permutation algorithm.
|
- **perm1** is a sketch in the examples that shows a recursive permutation algorithm.
|
||||||
It generates all permutations of a given char string.
|
It generates all permutations of a given char string and allows you to process every instance.
|
||||||
It allows you to process every instance.
|
This sketch is added to this library as it fits in the context.
|
||||||
It is added to this library as it fits in the context.
|
|
||||||
|
|
||||||
|
|
||||||
### Experimental - large numbers
|
## Experimental
|
||||||
|
|
||||||
|
#### 32 bit numbers
|
||||||
|
|
||||||
- **void bigFactorial(uint32_t n, double &mantissa, uint32_t &exponent)**
|
- **void bigFactorial(uint32_t n, double &mantissa, uint32_t &exponent)**
|
||||||
returns a double mantissa between 0 and 10, and an integer exponent.
|
returns a double mantissa between 0 and 10, and an integer exponent.
|
||||||
@ -123,18 +135,18 @@ Not investigated what its maximum value is, but it should be higher than **51867
|
|||||||
of combinations is always smaller than number of permutations.
|
of combinations is always smaller than number of permutations.
|
||||||
|
|
||||||
|
|
||||||
#### Experimental - not investigated yet
|
#### 64 bit numbers- not investigated
|
||||||
|
|
||||||
To have support for huge numbers one could upgrade the code to use uint64_t as parameter and
|
To have support for huge numbers one could upgrade the code to use uint64_t as parameter and
|
||||||
internally but calculating these values could take a lot of time, although **bigPermutations64(n, k)**
|
internally but calculating these values could take a lot of time, although **bigPermutations64(n, k)**
|
||||||
and **bigCombinations64(n, k)** would work fast for small values of k.
|
and **bigCombinations64(n, k)** would work fast for small values of k.
|
||||||
|
|
||||||
- **void bigFactorial64(uint64_t n, double &mantissa, uint64_t &exponent)**
|
- **void bigFactorial64(uint64_t n, double &mantissa, uint64_t &exponent)**
|
||||||
returns a double mantissa between 0 and 10, and an integer exponent.
|
returns a double mantissa between 0 and 10, and an integer exponent.
|
||||||
- **void bigPermutation64(uint64_t n, uint64_t k, double &mantissa, uint64_t &exponent)**
|
- **void bigPermutation64(uint64_t n, uint64_t k, double &mantissa, uint64_t &exponent)**
|
||||||
returns a double mantissa between 0 and 10, and an integer exponent.
|
returns a double mantissa between 0 and 10, and an integer exponent.
|
||||||
- **void bigCombination64(uint64_t n, uint64_t k, double &mantissa, uint64_t &exponent)**
|
- **void bigCombination64(uint64_t n, uint64_t k, double &mantissa, uint64_t &exponent)**
|
||||||
returns a double mantissa between 0 and 10, and an integer exponent.
|
returns a double mantissa between 0 and 10, and an integer exponent.
|
||||||
|
|
||||||
If someone has found the limits of these 64 bit versions, please let me know.
|
If someone has found the limits of these 64 bit versions, please let me know.
|
||||||
|
|
||||||
@ -146,9 +158,22 @@ See examples
|
|||||||
|
|
||||||
## Future
|
## Future
|
||||||
|
|
||||||
- code & example for get Nth Permutation
|
#### Must
|
||||||
- investigate valid range detection for a given (n, k) for combinations and permutations.
|
|
||||||
- investigate a bigFloat class to do math for permutations and combinations to substantially larger values.
|
#### Should
|
||||||
- Look for optimizations
|
|
||||||
- Look for ways to extend the scope
|
- investigate valid range detection for a given (n, k) for combinations and permutations.
|
||||||
|
- Look for optimizations
|
||||||
|
|
||||||
|
|
||||||
|
#### Could
|
||||||
|
|
||||||
|
- investigate a bigFloat class to do math for permutations and combinations to substantially larger values.
|
||||||
|
- Look for ways to extend the scope
|
||||||
|
- **skipFactorial(uint32_t n, uint32_t skip)** == n x (n-skip) x (n -skip -skip) ... x S (depends on size of skip)
|
||||||
|
- e.g. skipFactorial(12, 4) = 12 x 8 x 4.
|
||||||
|
- skipFactorial(n, 2) == semiFactorial(n);
|
||||||
|
|
||||||
|
|
||||||
|
#### Wont
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "statHelpers",
|
"name": "statHelpers",
|
||||||
"keywords": "permutation, next permutation, nth permutation, combination, factorial, n over k, n out of k",
|
"keywords": "permutation, next permutation, nth permutation, combination, factorial, n over k, n out of k",
|
||||||
"description": "Arduino library with a number of statistic helper functions.",
|
"description": "Arduino library with a number of statistic helper functions. Experimental big numbers.",
|
||||||
"authors":
|
"authors":
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/statHelpers.git"
|
"url": "https://github.com/RobTillaart/statHelpers.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.6",
|
"version": "0.1.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name=statHelpers
|
name=statHelpers
|
||||||
version=0.1.6
|
version=0.1.7
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino library with a number of statistic helper functions.
|
sentence=Arduino library with a number of statistic helper functions.
|
||||||
paragraph= permutation, next permutation, nth permutation, combination, factorial, n over k, n out of k
|
paragraph= permutation, next permutation, nth permutation, combination, factorial, n over k, n out of k. Experimental big numbers.
|
||||||
category=Data Processing
|
category=Data Processing
|
||||||
url=https://github.com/RobTillaart/statHelpers
|
url=https://github.com/RobTillaart/statHelpers
|
||||||
architectures=*
|
architectures=*
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: statHelpers.cpp
|
// FILE: statHelpers.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.6
|
// VERSION: 0.1.7
|
||||||
// PURPOSE: Arduino library with a number of statistic helper functions.
|
// PURPOSE: Arduino library with a number of statistic helper functions.
|
||||||
// DATE: 2020-07-01
|
// DATE: 2020-07-01
|
||||||
// URL: https://github.com/RobTillaart/statHelpers
|
// URL: https://github.com/RobTillaart/statHelpers
|
||||||
@ -188,7 +188,10 @@ double stirling(uint8_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
// SEMIFACTORIAL
|
// SEMIFACTORIAL
|
||||||
|
//
|
||||||
|
|
||||||
// exact ==> 20!!
|
// exact ==> 20!!
|
||||||
uint32_t semiFactorial(uint8_t n)
|
uint32_t semiFactorial(uint8_t n)
|
||||||
@ -475,7 +478,7 @@ void bigCombinations(uint32_t n, uint32_t k, double &mantissa, uint32_t &exponen
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// EXPERIMENTAL 64 BIT
|
// EXPERIMENTAL 64 BIT (not tested)
|
||||||
//
|
//
|
||||||
void bigFactorial64(uint64_t n, double &mantissa, uint64_t &exponent)
|
void bigFactorial64(uint64_t n, double &mantissa, uint64_t &exponent)
|
||||||
{
|
{
|
||||||
@ -524,8 +527,9 @@ void bigPermutations64(uint64_t n, uint64_t k, double &mantissa, uint64_t &expon
|
|||||||
void bigCombinations64(uint64_t n, uint64_t k, double &mantissa, uint64_t &exponent)
|
void bigCombinations64(uint64_t n, uint64_t k, double &mantissa, uint64_t &exponent)
|
||||||
{
|
{
|
||||||
exponent = 0;
|
exponent = 0;
|
||||||
|
mantissa = 0;
|
||||||
if ((k == 0) || (k == n)) return;
|
if ((k == 0) || (k == n)) return;
|
||||||
if (k < (n-k)) k = n - k; // symmetry
|
if (k < (n-k)) k = n - k; // symmetry
|
||||||
|
|
||||||
double f = n;
|
double f = n;
|
||||||
uint64_t p = 2;
|
uint64_t p = 2;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: statHelpers.h
|
// FILE: statHelpers.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.6
|
// VERSION: 0.1.7
|
||||||
// PURPOSE: Arduino library with a number of statistic helper functions.
|
// PURPOSE: Arduino library with a number of statistic helper functions.
|
||||||
// DATE: 2020-07-01
|
// DATE: 2020-07-01
|
||||||
// URL: https://github.com/RobTillaart/statHelpers
|
// URL: https://github.com/RobTillaart/statHelpers
|
||||||
@ -11,7 +11,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
#define STATHELPERS_LIB_VERSION (F("0.1.6"))
|
#define STATHELPERS_LIB_VERSION (F("0.1.7"))
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -155,4 +155,6 @@ unittest(test_combinations)
|
|||||||
|
|
||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
// --------
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user