Skip to content

Instantly share code, notes, and snippets.

@kylebgorman
Last active November 27, 2023 19:22
Show Gist options
  • Save kylebgorman/1410194 to your computer and use it in GitHub Desktop.
Save kylebgorman/1410194 to your computer and use it in GitHub Desktop.
Just for fun: a C-based calculator for Yang's (2005; "On Productivity", Language Variation Yearbook) Tolerance function
/*
* Tolerance Principle calculator, based on:
*
* C. Yang (2005). On productivity. Language Variation Yearbook 5:333-370.
*
* Definition:
*
* The number of data points consistent with a rule R is given by N, and the
* number of exceptions to it by m. By Tolerance, R is productive iff:
*
* m < (N + m) / ln (N + m)
*
* To compile, run:
*
* cc tolerance.c -lm -o tolerance
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
unsigned int tolerance_point(unsigned int m, unsigned int N) { // do the work
unsigned int p = m + N;
return floor(p / log(p)); // implicit cast to unsigned int
}
int main(int argc, char* argv[]) {
if (argc != 3) {
fprintf(stderr, "\nSynposis:\n\n\ttolerance m N\n\nAborting.\n");
}
else {
unsigned int m = atoi(argv[1]);
unsigned int N = atoi(argv[2]);
unsigned int tp = tolerance_point(m, N);
if (m > tp) {
printf("No productive generalization: ");
printf("tolerance point %d < %d exceptions\n", tp, m);
}
else {
printf("The N's have it: ");
printf("tolerance point %d > %d exceptions\n", tp, m);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment