Last active
October 12, 2017 11:47
-
-
Save makoru-hikage/a9edba0c4013bb9355e2cab9d204b022 to your computer and use it in GitHub Desktop.
A simple implementation of summation notation in Python
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
""" | |
## Derived from here: | |
## https://math.stackexchange.com/questions/1694311/is-sigma-sigma-a-mathematical-way-of-doing-a-for-loop/1694322 | |
## (c) CC-BY-SA 3.0 | |
""" | |
## Definition | |
def sum_notation(i=0, end=1, f= lambda x : x): | |
return f(i) + sum_notation(i+1, end, f) if (i <= end) else 0 | |
## Usage | |
y = lambda x : 1 / (2 ** x) | |
print (sum_notation(0, 3)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use capital Sigma or capital Pi notation, use tail call recursion instead.