From 92353c1c67158b7eb32c80570f6baa13e0496528 Mon Sep 17 00:00:00 2001 From: portnov Date: Sun, 14 Dec 2008 21:31:34 +0500 Subject: [PATCH] Docstrings for classes --- data.py | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-) diff --git a/data.py b/data.py index 5008fdd..96f5c63 100644 --- a/data.py +++ b/data.py @@ -29,11 +29,13 @@ def is_nothing(x): return isinstance(x,NothingClass) def obj(x): + "Convert x to object - Const or anything else" if isinstance(x,float) or isinstance(x,int): return Const(x) return x def sqrt_(x): + "Square root for any type of object" if is_number(x): if x < 0: return Nothing @@ -47,6 +49,7 @@ def sqrt_(x): return Expr('sqrt',x,None) class NothingClass(object): + "This class represents `no result' value" def __repr__(self): return "Nothing" @@ -71,6 +74,7 @@ class NothingClass(object): Nothing = NothingClass() class Unknown(object): + "Unknown variable" def __init__(self,name='',add=True,value=None): self.name = name if add: @@ -103,6 +107,7 @@ class Unknown(object): return Expr('/',self,e) class Const(float): + "Numeric constant" def __init__(self,x): float.__init__(self,x) @@ -142,6 +147,7 @@ class Const(float): return Expr('*',self,e) class Line(object): + "Straight line" def __init__(self, A,B,C): self.A = A self.B = B @@ -195,6 +201,7 @@ def segment(name): return p class Segment(object): + "Segment of a straightline - class for syntax parser" def __init__(self,A,B): self.A = A self.B = B @@ -203,6 +210,7 @@ class Segment(object): return "[%s--%s]" % (self.A, self.B) class Sum(list): + "This class represents polynomials" def __repr__(self): return " + ".join(map(repr,self)) @@ -221,6 +229,7 @@ class Sum(list): return Sum(lst) class UD(object): + "Dictionary, which shows power for each unknown in Monoid" def __init__(self,dct): self.dict = {} for k,v in dct.iteritems(): @@ -314,6 +323,7 @@ class Monoid(object): return True class Expr(object): + "Generic expression class" def __init__(self,op,x,y): self.op = op self.x = x @@ -354,7 +364,7 @@ class Expr(object): elif self.op == '+': return Expr('+', self.x*e, self.y*e) return Expr('*',self,e) - + def __div__(self,e): if is_number(e): if self.op == '*': @@ -367,6 +377,7 @@ class Expr(object): return Expr('/',self,e) def to_sum(expr): + "Convert anything to Sum" if isinstance(expr,Monoid): return Sum([expr]) if isinstance(expr,Sum): @@ -384,6 +395,7 @@ def to_sum(expr): return to_sum(expr.x) * to_sum(expr.y) class Union(set): + "This class represents `many results' values" def __repr__(self): lst = list(self) return repr(lst) @@ -428,7 +440,7 @@ class Union(set): for x in self: n.add(x**e) return n - + def __div__(self,e): if isinstance(e,Union): n = Union() @@ -442,8 +454,6 @@ class Union(set): n.add(x/e) return n - - def collect_nums(sum): s = 0 r = Sum([]) -- 1.7.2.3