Last active
August 23, 2022 01:36
-
-
Save amstan/2865056 to your computer and use it in GitHub Desktop.
amstan function
This file contains hidden or 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
#!/usr/bin/env python3 | |
def bitlist(x): | |
return [float(d) for d in bin(x)[2:][::-1]] | |
def amstan(x,k=0): | |
"""Computes amstan's function. k=0 returns just a bitcount of x, k=1 returns just x, anything in between is magic!""" | |
bits=bitlist(x) | |
return sum(bit*(2.**(i*k)) for i,bit in enumerate(bits)) | |
def amstan_tester(x): | |
"""Tests a bunch of k values for the given x.""" | |
print("x=%s, bit list:%r" % (x,list(bitlist(x)))) | |
for i in range(-10,20): | |
k=i/10.0 | |
print("amstan(x=%s,k=%s)=\t%s" % (x,k,amstan(x,k))) | |
print() | |
if __name__=="__main__": | |
import matplotlib.pyplot as plt | |
print("Close matplotlib window to see the next k value graph") | |
for i in range(30): | |
k=i/10.0-1 | |
print(f"{k=}") | |
plt.plot([amstan(x,k) for x in range(2**8)]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment