/*
 # neighsize.c
 #
 # calculate exponential decay parameter for command arguments
 # number of iterations,
 # start value,
 # rate, and
 # lower threshold.
 #
 # one value -1 computes missing value
 # 
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char **argv) {

  double iter, start, rate, threshold;

  if(argc != 5) {
    printf("%s iter start decayrate threshold\n", argv[0]);
    printf("  start required! enter -1 for other values of interest\n");
    exit(1);
  }

  iter = atof(argv[1]);
  start = atof(argv[2]);
  rate = atof(argv[3]);
  threshold = atof(argv[4]);

  if(threshold < 0. && iter > 0. && start > 0. && rate > 0.)
      printf("# decayto(%g(iter),%g(start),%.15f(decayrate)) = %g\n",
               iter, start, rate, threshold = start * pow(rate, iter));

  if(rate < 0. && iter > 0. && start > 0. && threshold > 0.)
      printf("# factor(%g(iter),%g(start),%g(threshold)) = %.15f\n",
          iter, start, threshold, rate = exp(log(threshold/start) / iter));

  if(iter < 0. && threshold > 0. && start > 0. && rate > 0.)
      printf("# iter(%g(start),%g(threshold),%.15f(decayrate)) = %g\n",
          start, threshold, rate, iter = log(threshold/start) / log(rate));

  printf("%g %g %.15f %g\n", iter, start, rate, threshold);

  return 0;
}
