0.1.7 statHelpers

This commit is contained in:
rob tillaart 2023-03-15 16:12:52 +01:00
parent 17f6553ac2
commit da98215f89
11 changed files with 67 additions and 29 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -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/).
## [0.1.7] - 2023-03-15
- update readme.md
- update GitHub actions
- update license 2023
- minor edits
## [0.1.6] - 2022-11-25
- Add RP2040 support to build-CI.
- Add CHANGELOG.md

View File

@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal

View File

@ -14,11 +14,20 @@ Arduino library with a number of statistic helper functions.
## Description
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
## Functions
## Interface
```cpp
#include "statHelpers.h"
```
### Permutation
@ -56,6 +65,8 @@ but accuracy is less than the **dfactorial()**, see example.
### SemiFactorial
SemiFactorials are like factorials but skipping every other.
- **uint32_t semiFactorial(n)** exact up to 20!!
- **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)
@ -64,6 +75,7 @@ SemiFactorial are defined for
- **odd** values: n x (n-2) x (n-4) ... x 1
- **even** values: n x (n-2) x (n-4) ... x 2
Notes:
```n! = n!! x (n-1)!!``` this formula allows to calculate the value of n! indirectly
@ -94,13 +106,13 @@ Uses Pascal's triangle.
## Notes
- **perm1** is a sketch in the examples that shows a recursive permutation algorithm.
It generates all permutations of a given char string.
It allows you to process every instance.
It is added to this library as it fits in the context.
It generates all permutations of a given char string and allows you to process every instance.
This sketch 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)**
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.
#### 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
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.
- **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)**
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)**
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.
@ -146,9 +158,22 @@ See examples
## Future
- code & example for get Nth Permutation
- 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.
- Look for optimizations
- Look for ways to extend the scope
#### Must
#### Should
- 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

View File

@ -1,7 +1,7 @@
{
"name": "statHelpers",
"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":
[
{
@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/statHelpers.git"
},
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,9 +1,9 @@
name=statHelpers
version=0.1.6
version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
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
url=https://github.com/RobTillaart/statHelpers
architectures=*

View File

@ -1,7 +1,7 @@
//
// FILE: statHelpers.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.6
// VERSION: 0.1.7
// PURPOSE: Arduino library with a number of statistic helper functions.
// DATE: 2020-07-01
// URL: https://github.com/RobTillaart/statHelpers
@ -188,7 +188,10 @@ double stirling(uint8_t n)
}
///////////////////////////////////////////////////////////////////////////
//
// SEMIFACTORIAL
//
// exact ==> 20!!
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)
{
@ -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)
{
exponent = 0;
mantissa = 0;
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;
uint64_t p = 2;

View File

@ -2,7 +2,7 @@
//
// FILE: statHelpers.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.6
// VERSION: 0.1.7
// PURPOSE: Arduino library with a number of statistic helper functions.
// DATE: 2020-07-01
// URL: https://github.com/RobTillaart/statHelpers
@ -11,7 +11,7 @@
#include "Arduino.h"
#define STATHELPERS_LIB_VERSION (F("0.1.6"))
#define STATHELPERS_LIB_VERSION (F("0.1.7"))
///////////////////////////////////////////////////////////////////////////

View File

@ -155,4 +155,6 @@ unittest(test_combinations)
unittest_main()
// --------
// -- END OF FILE --