
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * 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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * 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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-41) (not (<= x 1.65e+28))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-41) || !(x <= 1.65e+28)) {
tmp = x - (x * z);
} else {
tmp = x + (y * 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
real(8) :: tmp
if ((x <= (-4.5d-41)) .or. (.not. (x <= 1.65d+28))) then
tmp = x - (x * z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-41) || !(x <= 1.65e+28)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-41) or not (x <= 1.65e+28): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-41) || !(x <= 1.65e+28)) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e-41) || ~((x <= 1.65e+28))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-41], N[Not[LessEqual[x, 1.65e+28]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-41} \lor \neg \left(x \leq 1.65 \cdot 10^{+28}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -4.5e-41 or 1.65e28 < x Initial program 100.0%
Taylor expanded in x around inf 86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
sub-neg86.2%
distribute-rgt-in86.3%
*-un-lft-identity86.3%
distribute-lft-neg-in86.3%
unsub-neg86.3%
Applied egg-rr86.3%
if -4.5e-41 < x < 1.65e28Initial program 100.0%
Taylor expanded in y around inf 90.1%
*-commutative90.1%
Simplified90.1%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.05e-39) (not (<= x 1.25e+31))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e-39) || !(x <= 1.25e+31)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * 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
real(8) :: tmp
if ((x <= (-2.05d-39)) .or. (.not. (x <= 1.25d+31))) then
tmp = x * (1.0d0 - z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e-39) || !(x <= 1.25e+31)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.05e-39) or not (x <= 1.25e+31): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.05e-39) || !(x <= 1.25e+31)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.05e-39) || ~((x <= 1.25e+31))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.05e-39], N[Not[LessEqual[x, 1.25e+31]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-39} \lor \neg \left(x \leq 1.25 \cdot 10^{+31}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.05e-39 or 1.25000000000000007e31 < x Initial program 100.0%
Taylor expanded in x around inf 86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
if -2.05e-39 < x < 1.25000000000000007e31Initial program 100.0%
Taylor expanded in y around inf 90.1%
*-commutative90.1%
Simplified90.1%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2e+70) (not (<= y 2.4e-10))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2e+70) || !(y <= 2.4e-10)) {
tmp = y * z;
} else {
tmp = x * (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
real(8) :: tmp
if ((y <= (-2d+70)) .or. (.not. (y <= 2.4d-10))) then
tmp = y * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2e+70) || !(y <= 2.4e-10)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2e+70) or not (y <= 2.4e-10): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2e+70) || !(y <= 2.4e-10)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2e+70) || ~((y <= 2.4e-10))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2e+70], N[Not[LessEqual[y, 2.4e-10]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+70} \lor \neg \left(y \leq 2.4 \cdot 10^{-10}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.00000000000000015e70 or 2.4e-10 < y Initial program 100.0%
Taylor expanded in y around inf 90.8%
*-commutative90.8%
Simplified90.8%
Taylor expanded in x around inf 78.0%
+-commutative78.0%
associate-/l*77.9%
Simplified77.9%
Taylor expanded in x around 0 72.5%
*-commutative72.5%
Simplified72.5%
if -2.00000000000000015e70 < y < 2.4e-10Initial program 100.0%
Taylor expanded in x around inf 85.9%
mul-1-neg85.9%
unsub-neg85.9%
Simplified85.9%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e-124) (* y z) (if (<= z 3.2) x (* x (- z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e-124) {
tmp = y * z;
} else if (z <= 3.2) {
tmp = x;
} else {
tmp = x * -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
real(8) :: tmp
if (z <= (-1.05d-124)) then
tmp = y * z
else if (z <= 3.2d0) then
tmp = x
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e-124) {
tmp = y * z;
} else if (z <= 3.2) {
tmp = x;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e-124: tmp = y * z elif z <= 3.2: tmp = x else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e-124) tmp = Float64(y * z); elseif (z <= 3.2) tmp = x; else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.05e-124) tmp = y * z; elseif (z <= 3.2) tmp = x; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e-124], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.2], x, N[(x * (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-124}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -1.05e-124Initial program 100.0%
Taylor expanded in y around inf 68.2%
*-commutative68.2%
Simplified68.2%
Taylor expanded in x around inf 57.0%
+-commutative57.0%
associate-/l*54.8%
Simplified54.8%
Taylor expanded in x around 0 56.9%
*-commutative56.9%
Simplified56.9%
if -1.05e-124 < z < 3.2000000000000002Initial program 100.0%
Taylor expanded in z around 0 69.3%
if 3.2000000000000002 < z Initial program 100.0%
Taylor expanded in x around inf 73.7%
mul-1-neg73.7%
unsub-neg73.7%
Simplified73.7%
Taylor expanded in z around inf 72.7%
neg-mul-172.7%
Simplified72.7%
Final simplification65.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.05e-124) (not (<= z 1e-25))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-124) || !(z <= 1e-25)) {
tmp = y * 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 <= (-1.05d-124)) .or. (.not. (z <= 1d-25))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-124) || !(z <= 1e-25)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.05e-124) or not (z <= 1e-25): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.05e-124) || !(z <= 1e-25)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.05e-124) || ~((z <= 1e-25))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.05e-124], N[Not[LessEqual[z, 1e-25]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-124} \lor \neg \left(z \leq 10^{-25}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.05e-124 or 1.00000000000000004e-25 < z Initial program 100.0%
Taylor expanded in y around inf 55.1%
*-commutative55.1%
Simplified55.1%
Taylor expanded in x around inf 46.1%
+-commutative46.1%
associate-/l*44.2%
Simplified44.2%
Taylor expanded in x around 0 47.5%
*-commutative47.5%
Simplified47.5%
if -1.05e-124 < z < 1.00000000000000004e-25Initial program 100.0%
Taylor expanded in z around 0 73.7%
Final simplification56.7%
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * 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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Initial program 100.0%
(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 x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 32.7%
herbie shell --seed 2024165
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))