/usr/share/octave/packages/interval-2.1.0/@infsup/rdivide.m is in octave-interval 2.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | ## Copyright 2014-2016 Oliver Heimlich
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @documentencoding UTF-8
## @defop Method {@@infsup} rdivide (@var{X}, @var{Y})
## @defopx Operator {@@infsup} {@var{X} ./ @var{Y}}
##
## Divide all numbers of interval @var{X} by all numbers of @var{Y}.
##
## For @var{X} = 1 compute the reciprocal of @var{Y}. Thus this function can
## compute @code{recip} as defined by IEEE Std 1788-2015.
##
## Accuracy: The result is a tight enclosure.
##
## @example
## @group
## x = infsup (2, 3);
## y = infsup (1, 2);
## x ./ y
## @result{} ans = [1, 3]
## @end group
## @end example
## @seealso{@@infsup/times}
## @end defop
## Author: Oliver Heimlich
## Keywords: interval
## Created: 2014-09-30
function result = rdivide (x, y)
if (nargin ~= 2)
print_usage ();
return
endif
if (not (isa (x, "infsup")))
x = infsup (x);
endif
if (not (isa (y, "infsup")))
y = infsup (y);
elseif (isa (y, "infsupdec"))
## Workaround for bug #42735
result = rdivide (x, y);
return
endif
## Short-circuit evaluation for 1 ./ x
if (all (vec (x.inf == 1 & x.sup == 1)))
result = recip (y);
## Resize, if scalar × matrix
if (not (size_equal (x.inf, y.inf)))
result.inf = ones (size (x.inf)) .* result.inf;
result.sup = ones (size (x.inf)) .* result.sup;
endif
return
endif
## Resize, if scalar × matrix
if (not (size_equal (x.inf, y.inf)))
x.inf = ones (size (y.inf)) .* x.inf;
x.sup = ones (size (y.inf)) .* x.sup;
y.inf = ones (size (x.inf)) .* y.inf;
y.sup = ones (size (x.inf)) .* y.sup;
endif
## Partitionize the function's domain
q1 = x.sup <= 0 & y.sup < 0;
q2 = x.sup <= 0 & y.inf > 0;
q3 = x.sup <= 0 & y.sup == 0;
q4 = x.sup <= 0 & y.sup > 0 & y.inf == 0;
q5 = x.inf >= 0 & x.sup > 0 & y.sup < 0;
q6 = x.inf >= 0 & x.sup > 0 & y.inf > 0;
q7 = x.inf >= 0 & x.sup > 0 & y.sup == 0;
q8 = x.inf >= 0 & x.sup > 0 & y.sup > 0 & y.inf == 0;
q9 = x.inf < 0 & 0 < x.sup & y.sup < 0;
q10 = x.inf < 0 & 0 < x.sup & y.inf > 0;
l = u = zeros (size (x.inf));
l (q1) = mpfr_function_d ('rdivide', -inf, x.sup(q1), y.inf(q1));
l (q2) = mpfr_function_d ('rdivide', -inf, x.inf(q2), y.inf(q2));
l (q3) = mpfr_function_d ('rdivide', -inf, x.sup(q3), y.inf(q3));
l (q4) = -inf;
l (q5) = mpfr_function_d ('rdivide', -inf, x.sup(q5), y.sup(q5));
l (q6) = mpfr_function_d ('rdivide', -inf, x.inf(q6), y.sup(q6));
l (q7) = -inf;
l (q8) = mpfr_function_d ('rdivide', -inf, x.inf(q8), y.sup(q8));
l (q9) = mpfr_function_d ('rdivide', -inf, x.sup(q9), y.sup(q9));
l (q10) = mpfr_function_d ('rdivide', -inf, x.inf(q10), y.inf(q10));
u (q1) = mpfr_function_d ('rdivide', +inf, x.inf(q1), y.sup(q1));
u (q2) = mpfr_function_d ('rdivide', +inf, x.sup(q2), y.sup(q2));
u (q3) = inf;
u (q4) = mpfr_function_d ('rdivide', +inf, x.sup(q4), y.sup(q4));
u (q5) = mpfr_function_d ('rdivide', +inf, x.inf(q5), y.inf(q5));
u (q6) = mpfr_function_d ('rdivide', +inf, x.sup(q6), y.inf(q6));
u (q7) = mpfr_function_d ('rdivide', +inf, x.inf(q7), y.inf(q7));
u (q8) = inf;
u (q9) = mpfr_function_d ('rdivide', +inf, x.inf(q9), y.sup(q9));
u (q10) = mpfr_function_d ('rdivide', +inf, x.sup(q10), y.inf(q10));
entireresult = (y.inf < 0 & y.sup > 0) | (x.inf < 0 & x.sup > 0 & ...
(y.inf == 0 | y.sup == 0));
l(entireresult) = -inf;
u(entireresult) = inf;
zeroresult = x.inf == 0 & x.sup == 0;
l(zeroresult) = u(zeroresult) = 0;
l(l == 0) = -0;
emptyresult = isempty (x) | isempty (y) | (y.inf == 0 & y.sup == 0);
l(emptyresult) = inf;
u(emptyresult) = -inf;
result = infsup ();
result.inf = l;
result.sup = u;
endfunction
function result = recip (x)
## Compute the reciprocal of @var{X}.
##
## The result is equivalent to @code{1 ./ @var{X}}, but is computed more
## efficiently.
##
## Accuracy: The result is a tight enclosure.
l = inf (size (x.inf));
u = -l;
## Fix signs to make use of limit values for 1 ./ x.
x.inf(x.inf == 0) = +0;
x.sup(x.sup == 0) = -0;
select = (x.inf >= 0 | x.sup <= 0) & ...
# undefined for x = [0, 0]
not (x.inf == 0 & x.sup == 0) & ...
# x is not empty
x.inf < inf;
if (any (select(:)))
## recip is monotonically decreasing
l(select) = mpfr_function_d ('rdivide', -inf, 1, x.sup(select));
u(select) = mpfr_function_d ('rdivide', +inf, 1, x.inf(select));
endif
## singularity at x = 0
select = x.inf < 0 & x.sup > 0;
if (any (select(:)))
l(select) = -inf;
u(select) = +inf;
endif
l(l == 0) = -0;
result = infsup ();
result.inf = l;
result.sup = u;
endfunction
%!# from the documentation string
%!assert (infsup (2, 3) ./ infsup (1, 2) == infsup (1, 3));
%!assert (1 ./ infsup (1, 4) == infsup (0.25, 1));
|