(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x (+ (- y z) 1.0)) z))
(t_1 (- (+ (/ x z) (* y (/ x z))) x)))
(if (<= t_0 -5e+217)
t_1
(if (<= t_0 5e+236) (- (+ (/ x z) (/ (* x y) z)) x) t_1))))double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
double t_0 = (x * ((y - z) + 1.0)) / z;
double t_1 = ((x / z) + (y * (x / z))) - x;
double tmp;
if (t_0 <= -5e+217) {
tmp = t_1;
} else if (t_0 <= 5e+236) {
tmp = ((x / z) + ((x * y) / z)) - x;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * ((y - z) + 1.0d0)) / z
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (x * ((y - z) + 1.0d0)) / z
t_1 = ((x / z) + (y * (x / z))) - x
if (t_0 <= (-5d+217)) then
tmp = t_1
else if (t_0 <= 5d+236) then
tmp = ((x / z) + ((x * y) / z)) - x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
public static double code(double x, double y, double z) {
double t_0 = (x * ((y - z) + 1.0)) / z;
double t_1 = ((x / z) + (y * (x / z))) - x;
double tmp;
if (t_0 <= -5e+217) {
tmp = t_1;
} else if (t_0 <= 5e+236) {
tmp = ((x / z) + ((x * y) / z)) - x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): return (x * ((y - z) + 1.0)) / z
def code(x, y, z): t_0 = (x * ((y - z) + 1.0)) / z t_1 = ((x / z) + (y * (x / z))) - x tmp = 0 if t_0 <= -5e+217: tmp = t_1 elif t_0 <= 5e+236: tmp = ((x / z) + ((x * y) / z)) - x else: tmp = t_1 return tmp
function code(x, y, z) return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z) end
function code(x, y, z) t_0 = Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z) t_1 = Float64(Float64(Float64(x / z) + Float64(y * Float64(x / z))) - x) tmp = 0.0 if (t_0 <= -5e+217) tmp = t_1; elseif (t_0 <= 5e+236) tmp = Float64(Float64(Float64(x / z) + Float64(Float64(x * y) / z)) - x); else tmp = t_1; end return tmp end
function tmp = code(x, y, z) tmp = (x * ((y - z) + 1.0)) / z; end
function tmp_2 = code(x, y, z) t_0 = (x * ((y - z) + 1.0)) / z; t_1 = ((x / z) + (y * (x / z))) - x; tmp = 0.0; if (t_0 <= -5e+217) tmp = t_1; elseif (t_0 <= 5e+236) tmp = ((x / z) + ((x * y) / z)) - x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x / z), $MachinePrecision] + N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+217], t$95$1, If[LessEqual[t$95$0, 5e+236], N[(N[(N[(x / z), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], t$95$1]]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\
t_1 := \left(\frac{x}{z} + y \cdot \frac{x}{z}\right) - x\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+217}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+236}:\\
\;\;\;\;\left(\frac{x}{z} + \frac{x \cdot y}{z}\right) - x\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 10.2 |
|---|---|
| Target | 0.5 |
| Herbie | 0.1 |
if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < -5.00000000000000041e217 or 4.9999999999999997e236 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) Initial program 40.2
Simplified13.5
Taylor expanded in y around 0 13.5
Applied egg-rr0.1
if -5.00000000000000041e217 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 4.9999999999999997e236Initial program 0.1
Simplified0.1
Taylor expanded in y around 0 0.1
Final simplification0.1
herbie shell --seed 2022207
(FPCore (x y z)
:name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))
(/ (* x (+ (- y z) 1.0)) z))