python 2.7 - How to restrict sympy FiniteSet containing symbol -
i new sympy. tried solve system of linear equations linsolve(). yields solution can reproduced 2 following lines.
d = symbols("d") solution = sets.finiteset((d + 1, -d + 4, -d + 5, d))
my solution obeys restriction, 4 values must positive integers. happens d = 0, 1, 2, 3, 4.
i able evaluate solution @ fixed d (e. g. d = 0) with
solution.subs({d : 0})
what have restrict set of solutions valid ones automatically. mathematically amounts intersection \mathbb{n^0}^4. in practice output from
for d_fixed in range(5): solution.subs({d : d_fixed})
i. e.
{(1, 4, 5, 0)} {(2, 3, 4, 1)} {(3, 2, 3, 2)} {(4, 1, 2, 3)} {(5, 0, 1, 4)}
how can this?
i think along these lines it, little magic you.
>>> sympy import * >>> var('d') d >>> solution = sets.finiteset((d+1,-d+4,-d+5,d)) >>> list(list(solution)[0]) [d + 1, -d + 4, -d + 5, d] >>> sympy.solvers.inequalities import reduce_inequalities >>> reduce_inequalities([0<=d + 1, 0<=-d + 4, 0<=-d + 5, 0<=d],[d]) and(0 <= d, d <= 4)
i indebted https://stackoverflow.com/users/1879010/dietrich comment have been forgetting read until saw question.
Comments
Post a Comment