
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -8e+241)
t_0
(if (<= z -1.6e+200)
(* y z)
(if (<= z -1e+81)
t_0
(if (<= z -2.4e+47)
(* y z)
(if (<= z -760000000000.0)
t_0
(if (<= z -1.2e-39)
(* y z)
(if (<= z 3.9e-98)
x
(if (or (<= z 3.3e+14)
(and (not (<= z 3.4e+26)) (<= z 8.6e+200)))
(* y z)
t_0))))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -8e+241) {
tmp = t_0;
} else if (z <= -1.6e+200) {
tmp = y * z;
} else if (z <= -1e+81) {
tmp = t_0;
} else if (z <= -2.4e+47) {
tmp = y * z;
} else if (z <= -760000000000.0) {
tmp = t_0;
} else if (z <= -1.2e-39) {
tmp = y * z;
} else if (z <= 3.9e-98) {
tmp = x;
} else if ((z <= 3.3e+14) || (!(z <= 3.4e+26) && (z <= 8.6e+200))) {
tmp = y * 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 = x * -z
if (z <= (-8d+241)) then
tmp = t_0
else if (z <= (-1.6d+200)) then
tmp = y * z
else if (z <= (-1d+81)) then
tmp = t_0
else if (z <= (-2.4d+47)) then
tmp = y * z
else if (z <= (-760000000000.0d0)) then
tmp = t_0
else if (z <= (-1.2d-39)) then
tmp = y * z
else if (z <= 3.9d-98) then
tmp = x
else if ((z <= 3.3d+14) .or. (.not. (z <= 3.4d+26)) .and. (z <= 8.6d+200)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -8e+241) {
tmp = t_0;
} else if (z <= -1.6e+200) {
tmp = y * z;
} else if (z <= -1e+81) {
tmp = t_0;
} else if (z <= -2.4e+47) {
tmp = y * z;
} else if (z <= -760000000000.0) {
tmp = t_0;
} else if (z <= -1.2e-39) {
tmp = y * z;
} else if (z <= 3.9e-98) {
tmp = x;
} else if ((z <= 3.3e+14) || (!(z <= 3.4e+26) && (z <= 8.6e+200))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -8e+241: tmp = t_0 elif z <= -1.6e+200: tmp = y * z elif z <= -1e+81: tmp = t_0 elif z <= -2.4e+47: tmp = y * z elif z <= -760000000000.0: tmp = t_0 elif z <= -1.2e-39: tmp = y * z elif z <= 3.9e-98: tmp = x elif (z <= 3.3e+14) or (not (z <= 3.4e+26) and (z <= 8.6e+200)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -8e+241) tmp = t_0; elseif (z <= -1.6e+200) tmp = Float64(y * z); elseif (z <= -1e+81) tmp = t_0; elseif (z <= -2.4e+47) tmp = Float64(y * z); elseif (z <= -760000000000.0) tmp = t_0; elseif (z <= -1.2e-39) tmp = Float64(y * z); elseif (z <= 3.9e-98) tmp = x; elseif ((z <= 3.3e+14) || (!(z <= 3.4e+26) && (z <= 8.6e+200))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -8e+241) tmp = t_0; elseif (z <= -1.6e+200) tmp = y * z; elseif (z <= -1e+81) tmp = t_0; elseif (z <= -2.4e+47) tmp = y * z; elseif (z <= -760000000000.0) tmp = t_0; elseif (z <= -1.2e-39) tmp = y * z; elseif (z <= 3.9e-98) tmp = x; elseif ((z <= 3.3e+14) || (~((z <= 3.4e+26)) && (z <= 8.6e+200))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -8e+241], t$95$0, If[LessEqual[z, -1.6e+200], N[(y * z), $MachinePrecision], If[LessEqual[z, -1e+81], t$95$0, If[LessEqual[z, -2.4e+47], N[(y * z), $MachinePrecision], If[LessEqual[z, -760000000000.0], t$95$0, If[LessEqual[z, -1.2e-39], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.9e-98], x, If[Or[LessEqual[z, 3.3e+14], And[N[Not[LessEqual[z, 3.4e+26]], $MachinePrecision], LessEqual[z, 8.6e+200]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -8 \cdot 10^{+241}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.6 \cdot 10^{+200}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{+47}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -760000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-39}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{-98}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.3 \cdot 10^{+14} \lor \neg \left(z \leq 3.4 \cdot 10^{+26}\right) \land z \leq 8.6 \cdot 10^{+200}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -8.0000000000000004e241 or -1.60000000000000016e200 < z < -9.99999999999999921e80 or -2.40000000000000019e47 < z < -7.6e11 or 3.3e14 < z < 3.4000000000000003e26 or 8.60000000000000062e200 < z Initial program 100.0%
Taylor expanded in x around inf 77.0%
mul-1-neg77.0%
unsub-neg77.0%
Simplified77.0%
Taylor expanded in z around inf 76.6%
associate-*r*76.6%
mul-1-neg76.6%
Simplified76.6%
if -8.0000000000000004e241 < z < -1.60000000000000016e200 or -9.99999999999999921e80 < z < -2.40000000000000019e47 or -7.6e11 < z < -1.20000000000000008e-39 or 3.89999999999999971e-98 < z < 3.3e14 or 3.4000000000000003e26 < z < 8.60000000000000062e200Initial program 100.0%
Taylor expanded in y around inf 79.9%
*-commutative79.9%
Simplified79.9%
Taylor expanded in x around 0 68.9%
*-commutative68.9%
Simplified68.9%
if -1.20000000000000008e-39 < z < 3.89999999999999971e-98Initial program 100.0%
Taylor expanded in z around 0 77.3%
Final simplification74.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.8e-88) (not (<= x 1.95e-42))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-88) || !(x <= 1.95e-42)) {
tmp = x * (1.0 - z);
} else {
tmp = 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 <= (-8.8d-88)) .or. (.not. (x <= 1.95d-42))) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-88) || !(x <= 1.95e-42)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.8e-88) or not (x <= 1.95e-42): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.8e-88) || !(x <= 1.95e-42)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.8e-88) || ~((x <= 1.95e-42))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.8e-88], N[Not[LessEqual[x, 1.95e-42]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-88} \lor \neg \left(x \leq 1.95 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -8.8000000000000002e-88 or 1.9500000000000001e-42 < x Initial program 100.0%
Taylor expanded in x around inf 80.9%
mul-1-neg80.9%
unsub-neg80.9%
Simplified80.9%
if -8.8000000000000002e-88 < x < 1.9500000000000001e-42Initial program 100.0%
Taylor expanded in y around inf 96.1%
*-commutative96.1%
Simplified96.1%
Taylor expanded in x around 0 75.8%
*-commutative75.8%
Simplified75.8%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-39) (not (<= x 8.5e+56))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-39) || !(x <= 8.5e+56)) {
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 <= (-6.5d-39)) .or. (.not. (x <= 8.5d+56))) 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 <= -6.5e-39) || !(x <= 8.5e+56)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-39) or not (x <= 8.5e+56): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-39) || !(x <= 8.5e+56)) 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 <= -6.5e-39) || ~((x <= 8.5e+56))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-39], N[Not[LessEqual[x, 8.5e+56]], $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 -6.5 \cdot 10^{-39} \lor \neg \left(x \leq 8.5 \cdot 10^{+56}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -6.50000000000000027e-39 or 8.4999999999999998e56 < x Initial program 100.0%
Taylor expanded in x around inf 86.6%
mul-1-neg86.6%
unsub-neg86.6%
Simplified86.6%
if -6.50000000000000027e-39 < x < 8.4999999999999998e56Initial program 100.0%
Taylor expanded in y around inf 95.3%
*-commutative95.3%
Simplified95.3%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (<= x -6.5e-39) (- x (* x z)) (if (<= x 4.9e+58) (+ x (* y z)) (* x (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e-39) {
tmp = x - (x * z);
} else if (x <= 4.9e+58) {
tmp = x + (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 (x <= (-6.5d-39)) then
tmp = x - (x * z)
else if (x <= 4.9d+58) then
tmp = x + (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 (x <= -6.5e-39) {
tmp = x - (x * z);
} else if (x <= 4.9e+58) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.5e-39: tmp = x - (x * z) elif x <= 4.9e+58: tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.5e-39) tmp = Float64(x - Float64(x * z)); elseif (x <= 4.9e+58) tmp = Float64(x + 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 (x <= -6.5e-39) tmp = x - (x * z); elseif (x <= 4.9e+58) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.5e-39], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.9e+58], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-39}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{+58}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if x < -6.50000000000000027e-39Initial program 100.0%
Taylor expanded in x around inf 86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
Taylor expanded in z around 0 86.1%
mul-1-neg86.1%
sub-neg86.1%
Simplified86.1%
if -6.50000000000000027e-39 < x < 4.90000000000000018e58Initial program 100.0%
Taylor expanded in y around inf 95.3%
*-commutative95.3%
Simplified95.3%
if 4.90000000000000018e58 < x Initial program 100.0%
Taylor expanded in x around inf 87.3%
mul-1-neg87.3%
unsub-neg87.3%
Simplified87.3%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.26e-39) (not (<= z 1.4e-101))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.26e-39) || !(z <= 1.4e-101)) {
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.26d-39)) .or. (.not. (z <= 1.4d-101))) 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.26e-39) || !(z <= 1.4e-101)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.26e-39) or not (z <= 1.4e-101): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.26e-39) || !(z <= 1.4e-101)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.26e-39) || ~((z <= 1.4e-101))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.26e-39], N[Not[LessEqual[z, 1.4e-101]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.26 \cdot 10^{-39} \lor \neg \left(z \leq 1.4 \cdot 10^{-101}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.26e-39 or 1.39999999999999995e-101 < z Initial program 100.0%
Taylor expanded in y around inf 61.8%
*-commutative61.8%
Simplified61.8%
Taylor expanded in x around 0 54.5%
*-commutative54.5%
Simplified54.5%
if -1.26e-39 < z < 1.39999999999999995e-101Initial program 100.0%
Taylor expanded in z around 0 77.3%
Final simplification64.1%
(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%
Final simplification100.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 38.1%
Final simplification38.1%
herbie shell --seed 2023311
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))