def generateData(self): return [ { "expected": F.Multiplication(F.Variable('x'), F.Constant(2)), "f": F.Power(F.Variable('x'), F.Constant(2)), "rng": [(1, 100)], "N": 1_000 }, ]
def generateData(self): return [ { "expected": F.Addition(F.Constant(1), F.Constant(1)), "f": F.Addition(F.Variable('x'), F.Variable('x')) }, { "expected": F.Identity(F.Constant(1)), "f": F.Identity(F.Variable('x')) }, { "expected": F.Multiplication( F.Power(F.Variable('x'), F.Constant(2)), F.Addition( F.Division( F.Multiplication(F.Constant(1), F.Constant(2)), F.Variable('x')), F.Multiplication( F.Logarithm(F.Variable('x'), F.Constant(2.718)), F.Constant(0)))), "f": F.Power(F.Variable('x'), F.Constant(2)) }, ]
def __init__(self, f1, f2): if isinstance(f1, function.Function): self.f1 = f1 elif isinstance(f1, numbers.Number): self.f1 = function.Constant(f1) if isinstance(f2, function.Function): self.f2 = f2 elif isinstance(f2, numbers.Number): self.f2 = function.Constant(f2) self.exp = Exp() self.log = Log()
class OptimizeTest(ITest): data = [ { "expected": F.Constant(0), "func": F.Multiplication(0, 3) }, { "expected": F.Constant(0), "func": F.Multiplication(0, F.Multiplication(0, 3)) }, ] def generateData(self): return OptimizeTest.data def test(self, expected, func): opt = func.optimize() assert expected == opt, f"Error: expected: {expected}, but got: {opt} for {func}"
def parseUnit(element): if isNumber(element): return F.Constant(float(element)) elif isVariable(element): return F.Variable(name=element)
def get_derivative(self): return function.Constant(1) / (Cos() * Cos())
def get_derivative(self): return function.Constant(-1) * Sin()
def get_derivative(self): if self.degree == 0: return function.Constant(0) else: return Polynomial( [self.coeffs[i] * i for i in range(1, self.degree + 1)])
def get_derivative(self): if isinstance(self.b, function.Function): return ((function.Constant(1) / Log()(self.b)) * Log()).get_derivative() else: return ((function.Constant(1) / function.Constant(Log()(self.b))) * Log()).get_derivative()
def get_derivative(self): return function.Constant(1) / polynomial.Polynomial([0, 1])