Skip to content

Instantly share code, notes, and snippets.

@evincarofautumn
Created August 14, 2014 05:02
Show Gist options
  • Save evincarofautumn/3c2309e7941751573eb4 to your computer and use it in GitHub Desktop.
Save evincarofautumn/3c2309e7941751573eb4 to your computer and use it in GitHub Desktop.
Statistical manipulations in Kitten.
// “μσ” calculates the mean and standard deviation of a list, given the sum of the squares of the elements, the sum of the elements, and the reciprocal of the length. Uses real characters for more mathiness.
// With local variables, in infix:
def μσ (float float float → float float):
→ ss s in;
s ×. in → μ;
(ss ×. in −. μ sq) sqrt → σ;
μ σ
// With local variables, in postfix:
def μσ (float float float → float float):
→ ss s in;
s in (×.) → μ;
ss in (×.) μ sq (−.) sqrt → σ;
μ σ
// Eliminating σ:
def μσ (float float float → float float):
→ ss s in;
s in (×.) → μ;
μ
ss in (×.) μ sq (−.) sqrt
// Eliminating μ:
def μσ (float float float → float float):
→ ss s in;
s in (×.) dup
{ ss in (×.) } dip
sq (−.) sqrt
// Auxiliary definitions:
def sq (float → float): dup (×.)
def sqrt (float → float): …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment