Last active
November 27, 2023 19:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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