
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
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
public static double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
def code(x, y, z): return (x * ((y - z) + 1.0)) / z
function code(x, y, z) return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z) end
function tmp = code(x, y, z) tmp = (x * ((y - z) + 1.0)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
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
public static double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
def code(x, y, z): return (x * ((y - z) + 1.0)) / z
function code(x, y, z) return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z) end
function tmp = code(x, y, z) tmp = (x * ((y - z) + 1.0)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -4.6e+196) (- x) (if (<= z 1.16e+114) (/ (fma x (- y z) x) z) (- (/ x z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e+196) {
tmp = -x;
} else if (z <= 1.16e+114) {
tmp = fma(x, (y - z), x) / z;
} else {
tmp = (x / z) - x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -4.6e+196) tmp = Float64(-x); elseif (z <= 1.16e+114) tmp = Float64(fma(x, Float64(y - z), x) / z); else tmp = Float64(Float64(x / z) - x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -4.6e+196], (-x), If[LessEqual[z, 1.16e+114], N[(N[(x * N[(y - z), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+196}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 1.16 \cdot 10^{+114}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} - x\\
\end{array}
\end{array}
if z < -4.59999999999999961e196Initial program 63.7%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6495.7
Simplified95.7%
if -4.59999999999999961e196 < z < 1.15999999999999994e114Initial program 96.0%
Taylor expanded in x around 0
lower-/.f64N/A
sub-negN/A
associate-+r+N/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6496.0
Simplified96.0%
if 1.15999999999999994e114 < z Initial program 58.4%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
sub-negN/A
*-inversesN/A
metadata-evalN/A
distribute-lft-inN/A
associate-/l*N/A
*-rgt-identityN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6478.9
Simplified78.9%
(FPCore (x y z) :precision binary64 (if (<= z -4e+80) (- x) (if (<= z 2.95e+60) (/ (fma x y x) z) (- x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4e+80) {
tmp = -x;
} else if (z <= 2.95e+60) {
tmp = fma(x, y, x) / z;
} else {
tmp = -x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -4e+80) tmp = Float64(-x); elseif (z <= 2.95e+60) tmp = Float64(fma(x, y, x) / z); else tmp = Float64(-x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -4e+80], (-x), If[LessEqual[z, 2.95e+60], N[(N[(x * y + x), $MachinePrecision] / z), $MachinePrecision], (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+80}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{+60}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if z < -4e80 or 2.9500000000000001e60 < z Initial program 69.1%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6477.1
Simplified77.1%
if -4e80 < z < 2.9500000000000001e60Initial program 98.6%
Taylor expanded in z around 0
*-commutativeN/A
*-rgt-identityN/A
associate-*r*N/A
*-commutativeN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
lower-/.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
*-inversesN/A
associate-*r*N/A
*-rgt-identityN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6492.5
Simplified92.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (* x y) z))) (if (<= y -5.5e+58) t_0 (if (<= y 5.5e+44) (- (/ x z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -5.5e+58) {
tmp = t_0;
} else if (y <= 5.5e+44) {
tmp = (x / z) - x;
} else {
tmp = t_0;
}
return tmp;
}
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
if (y <= (-5.5d+58)) then
tmp = t_0
else if (y <= 5.5d+44) then
tmp = (x / z) - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -5.5e+58) {
tmp = t_0;
} else if (y <= 5.5e+44) {
tmp = (x / z) - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / z tmp = 0 if y <= -5.5e+58: tmp = t_0 elif y <= 5.5e+44: tmp = (x / z) - x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) / z) tmp = 0.0 if (y <= -5.5e+58) tmp = t_0; elseif (y <= 5.5e+44) tmp = Float64(Float64(x / z) - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) / z; tmp = 0.0; if (y <= -5.5e+58) tmp = t_0; elseif (y <= 5.5e+44) tmp = (x / z) - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -5.5e+58], t$95$0, If[LessEqual[y, 5.5e+44], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{z}\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+44}:\\
\;\;\;\;\frac{x}{z} - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.4999999999999999e58 or 5.5000000000000001e44 < y Initial program 86.8%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f6475.6
Simplified75.6%
if -5.4999999999999999e58 < y < 5.5000000000000001e44Initial program 86.7%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
sub-negN/A
*-inversesN/A
metadata-evalN/A
distribute-lft-inN/A
associate-/l*N/A
*-rgt-identityN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6494.5
Simplified94.5%
(FPCore (x y z) :precision binary64 (if (<= z -3350000000000.0) (- x) (if (<= z 45000.0) (/ x z) (- x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3350000000000.0) {
tmp = -x;
} else if (z <= 45000.0) {
tmp = x / z;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-3350000000000.0d0)) then
tmp = -x
else if (z <= 45000.0d0) then
tmp = x / z
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3350000000000.0) {
tmp = -x;
} else if (z <= 45000.0) {
tmp = x / z;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3350000000000.0: tmp = -x elif z <= 45000.0: tmp = x / z else: tmp = -x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3350000000000.0) tmp = Float64(-x); elseif (z <= 45000.0) tmp = Float64(x / z); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3350000000000.0) tmp = -x; elseif (z <= 45000.0) tmp = x / z; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3350000000000.0], (-x), If[LessEqual[z, 45000.0], N[(x / z), $MachinePrecision], (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3350000000000:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 45000:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if z < -3.35e12 or 45000 < z Initial program 75.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6467.1
Simplified67.1%
if -3.35e12 < z < 45000Initial program 99.9%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
sub-negN/A
*-inversesN/A
metadata-evalN/A
distribute-lft-inN/A
associate-/l*N/A
*-rgt-identityN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6451.2
Simplified51.2%
Taylor expanded in z around 0
lower-/.f6450.7
Simplified50.7%
(FPCore (x y z) :precision binary64 (- (/ x z) x))
double code(double x, double y, double z) {
return (x / z) - x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x / z) - x
end function
public static double code(double x, double y, double z) {
return (x / z) - x;
}
def code(x, y, z): return (x / z) - x
function code(x, y, z) return Float64(Float64(x / z) - x) end
function tmp = code(x, y, z) tmp = (x / z) - x; end
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z} - x
\end{array}
Initial program 86.7%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
sub-negN/A
*-inversesN/A
metadata-evalN/A
distribute-lft-inN/A
associate-/l*N/A
*-rgt-identityN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6459.6
Simplified59.6%
(FPCore (x y z) :precision binary64 (- x))
double code(double x, double y, double z) {
return -x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -x
end function
public static double code(double x, double y, double z) {
return -x;
}
def code(x, y, z): return -x
function code(x, y, z) return Float64(-x) end
function tmp = code(x, y, z) tmp = -x; end
code[x_, y_, z_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 86.7%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6437.0
Simplified37.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* (+ 1.0 y) (/ x z)) x)))
(if (< x -2.71483106713436e-162)
t_0
(if (< x 3.874108816439546e-197)
(* (* x (+ (- y z) 1.0)) (/ 1.0 z))
t_0))))
double code(double x, double y, double z) {
double t_0 = ((1.0 + y) * (x / z)) - x;
double tmp;
if (x < -2.71483106713436e-162) {
tmp = t_0;
} else if (x < 3.874108816439546e-197) {
tmp = (x * ((y - z) + 1.0)) * (1.0 / z);
} else {
tmp = t_0;
}
return tmp;
}
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 = ((1.0d0 + y) * (x / z)) - x
if (x < (-2.71483106713436d-162)) then
tmp = t_0
else if (x < 3.874108816439546d-197) then
tmp = (x * ((y - z) + 1.0d0)) * (1.0d0 / z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = ((1.0 + y) * (x / z)) - x;
double tmp;
if (x < -2.71483106713436e-162) {
tmp = t_0;
} else if (x < 3.874108816439546e-197) {
tmp = (x * ((y - z) + 1.0)) * (1.0 / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = ((1.0 + y) * (x / z)) - x tmp = 0 if x < -2.71483106713436e-162: tmp = t_0 elif x < 3.874108816439546e-197: tmp = (x * ((y - z) + 1.0)) * (1.0 / z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(1.0 + y) * Float64(x / z)) - x) tmp = 0.0 if (x < -2.71483106713436e-162) tmp = t_0; elseif (x < 3.874108816439546e-197) tmp = Float64(Float64(x * Float64(Float64(y - z) + 1.0)) * Float64(1.0 / z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = ((1.0 + y) * (x / z)) - x; tmp = 0.0; if (x < -2.71483106713436e-162) tmp = t_0; elseif (x < 3.874108816439546e-197) tmp = (x * ((y - z) + 1.0)) * (1.0 / z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(1.0 + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[Less[x, -2.71483106713436e-162], t$95$0, If[Less[x, 3.874108816439546e-197], N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 + y\right) \cdot \frac{x}{z} - x\\
\mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\
\;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
herbie shell --seed 2024215
(FPCore (x y z)
:name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (if (< x -67870776678359/25000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (+ 1 y) (/ x z)) x) (if (< x 1937054408219773/50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (* (* x (+ (- y z) 1)) (/ 1 z)) (- (* (+ 1 y) (/ x z)) x))))
(/ (* x (+ (- y z) 1.0)) z))