Пример #1
0
eqn = 'A = (B - 1/C)/(1 - (B*C)**2)'
assert set(_solve_zeros(eqn, var)) == set(['C = 0', 'B = 1/C'])
eqn = 'A = (B - 1/C)/(4 - (B*C)**2)'
assert set(_solve_zeros(eqn, var)) == set(['C = 0', 'B = 2/C'])
eqn = 'A = (B - 1/C)/(B - 1)**2'
assert set(_solve_zeros(eqn, var)) == set(['C = 0', 'B = 1'])
eqn = 'A = B + 1'
assert _solve_zeros(eqn, var) == []

eqn = 'A**2 + B*(2 - C) < C*A'
var = list('ABC')
res = simplify(eqn, variables=var, target=list('CAB'), all=True)
#print('\n#####\n'.join(res))
bylen = lambda x: len(x)
res = ['\n'.join(sorted(eqns.split('\n'), key=bylen)) for eqns in res]
assert equals(eqn, res[0].split('\n')[-1], dict(A=-0.9, B=1., C=1.))
assert equals(eqn, res[0].split('\n')[-1], dict(A=-0.9, B=1., C=-1.))
assert equals(eqn, res[0].split('\n')[-1], dict(A=1.1, B=-1., C=1.))
assert equals(eqn, res[0].split('\n')[-1], dict(A=1.1, B=-1., C=-1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=-1.1, B=1., C=1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=-1.1, B=1., C=-1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=0.9, B=-1., C=-1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=0.9, B=-1., C=1.))

res = simplify(eqn, variables=var, target=list('BCA'), all=True)
#print('\n#####\n'.join(res))
bylen = lambda x: len(x)
res = ['\n'.join(sorted(eqns.split('\n'), key=bylen)) for eqns in res]
assert equals(eqn, res[0].split('\n')[-1], dict(A=1., B=1., C=2.1))
assert equals(eqn, res[0].split('\n')[-1], dict(A=1., B=-1., C=2.1))
assert equals(eqn, res[0].split('\n')[-1], dict(A=-1., B=-1., C=2.1))
Пример #2
0
eqn = 'A = (B - 1/C)/(1 - (B*C)**2)'
assert set(_solve_zeros(eqn, var)) == set(['C = 0', 'B = 1/C'])
eqn = 'A = (B - 1/C)/(4 - (B*C)**2)'
assert set(_solve_zeros(eqn, var)) == set(['C = 0', 'B = 2/C'])
eqn = 'A = (B - 1/C)/(B - 1)**2'
assert set(_solve_zeros(eqn, var)) == set(['C = 0', 'B = 1'])
eqn = 'A = B + 1'
assert _solve_zeros(eqn, var) == []

eqn = 'A**2 + B*(2 - C) < C*A'
var = list('ABC')
res = simplify(eqn, variables=var, target=list('CAB'), all=True)
#print('\n#####\n'.join(res))
bylen = lambda x: len(x)
res = ['\n'.join(sorted(eqns.split('\n'), key=bylen)) for eqns in res]
assert equals(eqn, res[0].split('\n')[-1], dict(A=-0.9,B=1.,C=1.))
assert equals(eqn, res[0].split('\n')[-1], dict(A=-0.9,B=1.,C=-1.))
assert equals(eqn, res[0].split('\n')[-1], dict(A=1.1,B=-1.,C=1.))
assert equals(eqn, res[0].split('\n')[-1], dict(A=1.1,B=-1.,C=-1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=-1.1,B=1.,C=1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=-1.1,B=1.,C=-1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=0.9,B=-1.,C=-1.))
assert equals(eqn, res[1].split('\n')[-1], dict(A=0.9,B=-1.,C=1.))

res = simplify(eqn, variables=var, target=list('BCA'), all=True)
#print('\n#####\n'.join(res))
bylen = lambda x: len(x)
res = ['\n'.join(sorted(eqns.split('\n'), key=bylen)) for eqns in res]
assert equals(eqn, res[0].split('\n')[-1], dict(A=1.,B=1.,C=2.1))
assert equals(eqn, res[0].split('\n')[-1], dict(A=1.,B=-1.,C=2.1))
assert equals(eqn, res[0].split('\n')[-1], dict(A=-1.,B=-1.,C=2.1))