I was looking at the hypergeometric functions and related power-series calculations and I feel like there’s a common theme that could get broken out so I’m throwing this down here to get suggestions about whether there’s a design that makes sense. I will likely not get to it until after the survival-model related math functions are accurate and tested (a few weeks).
The motivation is that @thel suggested in the hypergeometric function PR to break out the “exp-log-sum-with-signs logic” into its own inline function but I can’t see how given that the logic needs to be state-aware over iterations (there’s a bool tracking the sign and it needs to be flipped when a negative term is multiplied by the product-so-far term. Looking at the other power-series based functions they all:
- have known or readily derived convergence conditions based on arguments
- set some initial values for accumulators
- maintain state in a product-so-far term
- maintain state in a sum-so-far term
- use or could use exp-log-sum-with-signs logic
- test for convergence based on the product-so-far term going to zero
- could rely on standard acceleration techniques for power series
There is a separate issue where these functions have optimizations or continuations that are relevant for portions of the range but my thought is to break those out into a function that just deals with branching to the right implementation and then write separate functions or functors for the implementations. The piece above just deals with power-series based implementations.