
(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 (- (/ (fma x y x) z) x))
double code(double x, double y, double z) {
return (fma(x, y, x) / z) - x;
}
function code(x, y, z) return Float64(Float64(fma(x, y, x) / z) - x) end
code[x_, y_, z_] := N[(N[(N[(x * y + x), $MachinePrecision] / z), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x
\end{array}
Initial program 90.0%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6490.0
Applied rewrites90.0%
lift-/.f64N/A
lift-fma.f64N/A
distribute-lft1-inN/A
+-commutativeN/A
lift-+.f64N/A
associate-*l/N/A
lift-+.f64N/A
lift--.f64N/A
lift--.f64N/A
div-addN/A
frac-addN/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
*-lft-identityN/A
lower-+.f64N/A
lower-*.f64N/A
lower-*.f6457.6
Applied rewrites57.6%
Taylor expanded in x around 0
unpow2N/A
associate-/r*N/A
distribute-lft-inN/A
div-addN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
div-add-revN/A
*-rgt-identityN/A
associate-*r/N/A
associate-/r*N/A
associate-*r*N/A
times-fracN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
distribute-lft-inN/A
div-addN/A
associate--l+N/A
Applied rewrites98.4%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.2e+49) (not (<= z 4.8e+84))) (- x) (/ (fma y x x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+49) || !(z <= 4.8e+84)) {
tmp = -x;
} else {
tmp = fma(y, x, x) / z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -5.2e+49) || !(z <= 4.8e+84)) tmp = Float64(-x); else tmp = Float64(fma(y, x, x) / z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2e+49], N[Not[LessEqual[z, 4.8e+84]], $MachinePrecision]], (-x), N[(N[(y * x + x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+49} \lor \neg \left(z \leq 4.8 \cdot 10^{+84}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, x\right)}{z}\\
\end{array}
\end{array}
if z < -5.19999999999999977e49 or 4.7999999999999999e84 < z Initial program 74.6%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6484.8
Applied rewrites84.8%
if -5.19999999999999977e49 < z < 4.7999999999999999e84Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6494.1
Applied rewrites94.1%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e+116) (not (<= y 1e+35))) (/ (* y x) z) (- (/ x z) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e+116) || !(y <= 1e+35)) {
tmp = (y * x) / z;
} else {
tmp = (x / z) - 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 ((y <= (-3.5d+116)) .or. (.not. (y <= 1d+35))) then
tmp = (y * x) / z
else
tmp = (x / z) - x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e+116) || !(y <= 1e+35)) {
tmp = (y * x) / z;
} else {
tmp = (x / z) - x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e+116) or not (y <= 1e+35): tmp = (y * x) / z else: tmp = (x / z) - x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e+116) || !(y <= 1e+35)) tmp = Float64(Float64(y * x) / z); else tmp = Float64(Float64(x / z) - x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.5e+116) || ~((y <= 1e+35))) tmp = (y * x) / z; else tmp = (x / z) - x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e+116], N[Not[LessEqual[y, 1e+35]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+116} \lor \neg \left(y \leq 10^{+35}\right):\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} - x\\
\end{array}
\end{array}
if y < -3.49999999999999997e116 or 9.9999999999999997e34 < y Initial program 95.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6483.0
Applied rewrites83.0%
if -3.49999999999999997e116 < y < 9.9999999999999997e34Initial program 86.5%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
*-inversesN/A
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6490.2
Applied rewrites90.2%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e+116) (not (<= y 1e+35))) (* (/ x z) y) (- (/ x z) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e+116) || !(y <= 1e+35)) {
tmp = (x / z) * y;
} else {
tmp = (x / z) - 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 ((y <= (-3.5d+116)) .or. (.not. (y <= 1d+35))) then
tmp = (x / z) * y
else
tmp = (x / z) - x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e+116) || !(y <= 1e+35)) {
tmp = (x / z) * y;
} else {
tmp = (x / z) - x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e+116) or not (y <= 1e+35): tmp = (x / z) * y else: tmp = (x / z) - x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e+116) || !(y <= 1e+35)) tmp = Float64(Float64(x / z) * y); else tmp = Float64(Float64(x / z) - x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.5e+116) || ~((y <= 1e+35))) tmp = (x / z) * y; else tmp = (x / z) - x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e+116], N[Not[LessEqual[y, 1e+35]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+116} \lor \neg \left(y \leq 10^{+35}\right):\\
\;\;\;\;\frac{x}{z} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} - x\\
\end{array}
\end{array}
if y < -3.49999999999999997e116 or 9.9999999999999997e34 < y Initial program 95.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6487.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.9
Applied rewrites87.9%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6481.8
Applied rewrites81.8%
if -3.49999999999999997e116 < y < 9.9999999999999997e34Initial program 86.5%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
*-inversesN/A
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6490.2
Applied rewrites90.2%
Final simplification86.9%
(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 90.0%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
*-inversesN/A
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6463.7
Applied rewrites63.7%
(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 90.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6438.1
Applied rewrites38.1%
(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 2024327
(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))