class Expr:
def __add__(self, other):
return Plus(self, other)
def __mul__(self, other):
return Times(self, other)
class Int(Expr):
def __init__(self, n):
self.n = n
def d(self, v):
return Int(0)
def __str__(self):
return `self.n`
class Var(Expr):
def __init__(self, var):
self.var = var
def d(self, v):
return Int(self.var == v and 1 or 0)
def __str__(self):
return self.var
class Plus(Expr):
def __init__(self, a, b):
self.e1 = a
self.e2 = b
def d(self, v):
return Plus(self.e1.d(v), self.e2.d(v))
def __str__(self):
return "(%s + %s)" % (self.e1, self.e2)
class Times(Expr):
def __init__(self, a, b):
self.e1 = a
self.e2 = b
def d(self, v):
return Plus(Times(self.e1, self.e2.d(v)), Times(self.e1.d(v), self.e2))
def __str__(self):
return "(%s * %s)" % (self.e1, self.e2)
if __name__ == "__main__":
x = Var("x")
a = Var("a")
b = Var("b")
c = Var("c")
e = a * x * x + b * x + c
print "d(%s, x) = %s" % (e, e.d("x"))
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有