(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)))
(if (<= t_0 -2e+274)
(- (* y (/ x z)) x)
(if (<= t_0 5e+305)
(- (+ (/ x z) (/ (* x y) z)) x)
(* x (+ -1.0 (/ (+ y 1.0) z)))))))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 tmp;
if (t_0 <= -2e+274) {
tmp = (y * (x / z)) - x;
} else if (t_0 <= 5e+305) {
tmp = ((x / z) + ((x * y) / z)) - x;
} else {
tmp = x * (-1.0 + ((y + 1.0) / z));
}
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) :: tmp
t_0 = (x * ((y - z) + 1.0d0)) / z
if (t_0 <= (-2d+274)) then
tmp = (y * (x / z)) - x
else if (t_0 <= 5d+305) then
tmp = ((x / z) + ((x * y) / z)) - x
else
tmp = x * ((-1.0d0) + ((y + 1.0d0) / z))
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 tmp;
if (t_0 <= -2e+274) {
tmp = (y * (x / z)) - x;
} else if (t_0 <= 5e+305) {
tmp = ((x / z) + ((x * y) / z)) - x;
} else {
tmp = x * (-1.0 + ((y + 1.0) / z));
}
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 tmp = 0 if t_0 <= -2e+274: tmp = (y * (x / z)) - x elif t_0 <= 5e+305: tmp = ((x / z) + ((x * y) / z)) - x else: tmp = x * (-1.0 + ((y + 1.0) / z)) 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) tmp = 0.0 if (t_0 <= -2e+274) tmp = Float64(Float64(y * Float64(x / z)) - x); elseif (t_0 <= 5e+305) tmp = Float64(Float64(Float64(x / z) + Float64(Float64(x * y) / z)) - x); else tmp = Float64(x * Float64(-1.0 + Float64(Float64(y + 1.0) / z))); 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; tmp = 0.0; if (t_0 <= -2e+274) tmp = (y * (x / z)) - x; elseif (t_0 <= 5e+305) tmp = ((x / z) + ((x * y) / z)) - x; else tmp = x * (-1.0 + ((y + 1.0) / z)); 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]}, If[LessEqual[t$95$0, -2e+274], N[(N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[t$95$0, 5e+305], N[(N[(N[(x / z), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], N[(x * N[(-1.0 + N[(N[(y + 1.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\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}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+274}:\\
\;\;\;\;y \cdot \frac{x}{z} - x\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+305}:\\
\;\;\;\;\left(\frac{x}{z} + \frac{x \cdot y}{z}\right) - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-1 + \frac{y + 1}{z}\right)\\
\end{array}
Results
| Original | 10.0 |
|---|---|
| Target | 0.4 |
| Herbie | 0.6 |
if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < -1.99999999999999984e274Initial program 52.1
Simplified17.9
Taylor expanded in y around inf 23.4
Simplified5.5
if -1.99999999999999984e274 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 5.00000000000000009e305Initial program 0.2
Simplified0.1
Taylor expanded in y around 0 0.1
if 5.00000000000000009e305 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) Initial program 62.8
Simplified19.2
Taylor expanded in x around 0 0.2
Applied egg-rr0.3
Taylor expanded in z around 0 0.2
Simplified0.2
Final simplification0.6
herbie shell --seed 2022185
(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))