Added cdf (aka Φ(x)) to the calculator, removed unneeded list comprehensions

Sat, 12 Dec 2015 04:04:10 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 12 Dec 2015 04:04:10 +0200
changeset 162
d24fe5e3e420
parent 161
6e7cb38f248d
child 163
ed3d52b37f19

Added cdf (aka Φ(x)) to the calculator, removed unneeded list comprehensions

calculator.py file | annotate | diff | comparison | revisions
hgpoll.py file | annotate | diff | comparison | revisions
hgrepo.py file | annotate | diff | comparison | revisions
mod_util.py file | annotate | diff | comparison | revisions
munge.py file | annotate | diff | comparison | revisions
--- a/calculator.py	Mon Oct 05 23:35:44 2015 +0300
+++ b/calculator.py	Sat Dec 12 04:04:10 2015 +0200
@@ -253,6 +253,7 @@
 	'sdword':		{ 'function': intf (lambda x: integerclamp (x, bits=32, signed=True)) },
 	'qword':		{ 'function': intf (lambda x: integerclamp (x, bits=64, signed=False)) },
 	'sqword':		{ 'function': intf (lambda x: integerclamp (x, bits=64, signed=True)) },
+	'cdf':			{ 'function': realf (lambda x: (1 + math.erf (x / math.sqrt(2))) / 2) },
 }
 
 Tokens = {'(', ')'}
@@ -270,6 +271,7 @@
 	'ε': 'epsilon',
 	'∨': '||',
 	'∧': '&&',
+	'Φ': 'cdf',
 }
 
 for name, value in Constants.items():
@@ -308,7 +310,7 @@
 
 Attributes['bin'] = Attributes['binary']
 Attributes['dec'] = Attributes['decimal']
-AttributeNames = sorted ([key for key in Attributes], key=lambda x:len(x), reverse=True)
+AttributeNames = sorted ((key for key in Attributes), key=lambda x:len(x), reverse=True)
 
 def is_int (x):
 	return math.fabs (x - math.floor(x)) < ε
@@ -424,8 +426,12 @@
 
 	def parse_symbol (self, expr):
 		for sym in Symbols:
-			if expr[:len (sym)].lower() == sym.lower():
-				return sym.lower()
+			if len(sym) == 1 and ord(sym) > 256:
+				if expr[0] == sym:
+					return sym
+			else:
+				if expr[:len (sym)].lower() == sym.lower():
+					return sym.lower()
 
 		return None
 
--- a/hgpoll.py	Mon Oct 05 23:35:44 2015 +0300
+++ b/hgpoll.py	Sat Dec 12 04:04:10 2015 +0200
@@ -77,7 +77,7 @@
 			comms=['log', 'incoming', 'pull', 'commit', 'push', 'outgoing', 'strip', 'transplant']
 			try:
 				with open (os.path.join (repo.name, '.hg', 'hgrc'), 'a') as fp:
-					fp.write ('\n[alias]\n' + ''.join(['%s=%s\n' % (x, x) for x in comms]))
+					fp.write ('\n[alias]\n' + ''.join('%s=%s\n' % (x, x) for x in comms))
 			except Exception as e:
 				print ('Warning: unable to alter hgrc of %s: %s' % repo.name, e)
 			print ('Cloning done.')
--- a/hgrepo.py	Mon Oct 05 23:35:44 2015 +0300
+++ b/hgrepo.py	Sat Dec 12 04:04:10 2015 +0200
@@ -57,7 +57,7 @@
 		return os.path.isdir (os.path.join (self.name, '.hg'))
 
 	def split_template (self, kvargs, separator):
-		return separator.join (['{%s}' % x[1] for x in kvargs.items()])
+		return separator.join ('{%s}' % x[1] for x in kvargs.items())
 
 	def merge_template (self, data, args):
 		result = {}
--- a/mod_util.py	Mon Oct 05 23:35:44 2015 +0300
+++ b/mod_util.py	Sat Dec 12 04:04:10 2015 +0200
@@ -124,8 +124,8 @@
 @modulecore.irc_command()
 def calcfunctions (bot, reply, **rest):
 	'''Lists the functions supported by .calc.'''
-	reply ('Available functions for .calc: %s' % \
-		', '.join (sorted ([name for name, data in calc.Functions.items()])))
+	names = ', '.join (sorted (name for name, data in calculator.Functions.items()))
+	reply ('Available functions for .calc:', names)
 
 @modulecore.irc_command (args='<expression...>')
 def calc (bot, reply, args, **rest):
--- a/munge.py	Mon Oct 05 23:35:44 2015 +0300
+++ b/munge.py	Sat Dec 12 04:04:10 2015 +0200
@@ -21,4 +21,4 @@
 	'''
 	Munges the given string
 	'''
-	return ''.join ([mungeone (ch) for ch in a])
+	return ''.join (mungeone(ch) for ch in a)

mercurial