You can actually allow a little bit of duplication. The second formula avoids this issue by having each input interval only appear in one place. It can't know that those two things can't happen at the same time. If the divisor turns out to be at its interval's maximum bound ( b), it might be dividing a dividend at its minimum bound ( a). The division code however, has to assume that each of its arguments is independent of the other. Your div_interval function will compute the result to be (a/b, b/a), when by basic algebra, we know the result should be (1, 1) (since any number divided by itself is 1). That's because the code doesn't know that a result at one extreme for one of the copies of the interval must also mean the same same extreme for the other one.Ĭonsider the calculation of r / r, for the interval r = (a, b). When the same interval is part of both the divisor and the dividend, you'll get a wider interval than you should. When your division function computes the reciprocal of its second argument, it reverses the order of the interval boundaries, so the upper bound of the input effects the lower bound of the output. The real issue here is that in par1, your r1 and r2 intervals both appear on both sides of a division operation. It's only when you're testing for exact equality or when you've combined a large number of floating point computations that the error might become significant. Floating point rounding can be a real issue, but for most computations (including the ones here) the error is very, very small. I'm afraid your reasoning for why the two functions give different results is not correct. The reason for different interval is due to IEEE floating point format, where every div_interval lose precision. We notice the different outcome from par1 and par2, which compute by different but algebraically equivalent expressions.įor the above given input r1 and r2, below is the computation. > str_interval(mul_interval(interval(-1, 2), interval(4, 8))) """Return the interval that contains the product of any value in x and any > str_interval(add_interval(interval(-1, 2), interval(4, 8))) """Return an interval that contains the sum of any value in interval x and Return ''.format(lower_bound(x), upper_bound(x)) > str_interval(div_interval(interval(-1, 2), interval(4, 8)))Īssert (lower_bound(y) > 0 or upper_bound(y) > str_interval(interval(-1, 2)) """Return the interval that contains the quotient of any value in x dividedĭivision is implemented as the multiplication of x by the reciprocal of y. Return div_interval(one, add_interval(rep_r1, rep_r2))īelow is an interval arithmetic abstraction that is used by aforementioned functions par1 and par2. Return div_interval(mul_interval(r1, r2), add_interval(r1, r2)) Below two algebraically equivalent formula for parallel resistors: par1(r1, r2) = (r1 * r2) / (r1 + r2), orįollowing two python functions, each of which computes the parallel_resistors formula : def par1(r1, r2):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |