
(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 99.9%
+-commutative99.9%
fma-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.15e-58)
(not
(or (<= x -9.9e-144)
(and (not (<= x -1.3e-189))
(or (<= x 4.6e-200)
(and (not (<= x 1.3e-119)) (<= x 2.7e-13)))))))
(* x (- 1.0 z))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e-58) || !((x <= -9.9e-144) || (!(x <= -1.3e-189) && ((x <= 4.6e-200) || (!(x <= 1.3e-119) && (x <= 2.7e-13)))))) {
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 <= (-1.15d-58)) .or. (.not. (x <= (-9.9d-144)) .or. (.not. (x <= (-1.3d-189))) .and. (x <= 4.6d-200) .or. (.not. (x <= 1.3d-119)) .and. (x <= 2.7d-13))) 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 <= -1.15e-58) || !((x <= -9.9e-144) || (!(x <= -1.3e-189) && ((x <= 4.6e-200) || (!(x <= 1.3e-119) && (x <= 2.7e-13)))))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.15e-58) or not ((x <= -9.9e-144) or (not (x <= -1.3e-189) and ((x <= 4.6e-200) or (not (x <= 1.3e-119) and (x <= 2.7e-13))))): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.15e-58) || !((x <= -9.9e-144) || (!(x <= -1.3e-189) && ((x <= 4.6e-200) || (!(x <= 1.3e-119) && (x <= 2.7e-13)))))) 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 <= -1.15e-58) || ~(((x <= -9.9e-144) || (~((x <= -1.3e-189)) && ((x <= 4.6e-200) || (~((x <= 1.3e-119)) && (x <= 2.7e-13))))))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.15e-58], N[Not[Or[LessEqual[x, -9.9e-144], And[N[Not[LessEqual[x, -1.3e-189]], $MachinePrecision], Or[LessEqual[x, 4.6e-200], And[N[Not[LessEqual[x, 1.3e-119]], $MachinePrecision], LessEqual[x, 2.7e-13]]]]]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-58} \lor \neg \left(x \leq -9.9 \cdot 10^{-144} \lor \neg \left(x \leq -1.3 \cdot 10^{-189}\right) \land \left(x \leq 4.6 \cdot 10^{-200} \lor \neg \left(x \leq 1.3 \cdot 10^{-119}\right) \land x \leq 2.7 \cdot 10^{-13}\right)\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.1499999999999999e-58 or -9.90000000000000042e-144 < x < -1.2999999999999999e-189 or 4.60000000000000015e-200 < x < 1.30000000000000006e-119 or 2.70000000000000011e-13 < x Initial program 99.9%
Taylor expanded in x around inf 84.6%
mul-1-neg84.6%
unsub-neg84.6%
Simplified84.6%
if -1.1499999999999999e-58 < x < -9.90000000000000042e-144 or -1.2999999999999999e-189 < x < 4.60000000000000015e-200 or 1.30000000000000006e-119 < x < 2.70000000000000011e-13Initial program 100.0%
Taylor expanded in y around inf 89.9%
*-commutative89.9%
Simplified89.9%
Taylor expanded in y around inf 89.9%
Taylor expanded in y around inf 79.9%
Final simplification82.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -1.7e+53)
t_0
(if (<= z -5.2e-60)
(* y z)
(if (<= z -5.8e-164)
x
(if (<= z -2.2e-170)
(* y z)
(if (<= z 1.0) x (if (<= z 1.15e+171) t_0 (* y z)))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.7e+53) {
tmp = t_0;
} else if (z <= -5.2e-60) {
tmp = y * z;
} else if (z <= -5.8e-164) {
tmp = x;
} else if (z <= -2.2e-170) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 1.15e+171) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-1.7d+53)) then
tmp = t_0
else if (z <= (-5.2d-60)) then
tmp = y * z
else if (z <= (-5.8d-164)) then
tmp = x
else if (z <= (-2.2d-170)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else if (z <= 1.15d+171) then
tmp = t_0
else
tmp = y * z
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 <= -1.7e+53) {
tmp = t_0;
} else if (z <= -5.2e-60) {
tmp = y * z;
} else if (z <= -5.8e-164) {
tmp = x;
} else if (z <= -2.2e-170) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 1.15e+171) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.7e+53: tmp = t_0 elif z <= -5.2e-60: tmp = y * z elif z <= -5.8e-164: tmp = x elif z <= -2.2e-170: tmp = y * z elif z <= 1.0: tmp = x elif z <= 1.15e+171: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -1.7e+53) tmp = t_0; elseif (z <= -5.2e-60) tmp = Float64(y * z); elseif (z <= -5.8e-164) tmp = x; elseif (z <= -2.2e-170) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; elseif (z <= 1.15e+171) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -1.7e+53) tmp = t_0; elseif (z <= -5.2e-60) tmp = y * z; elseif (z <= -5.8e-164) tmp = x; elseif (z <= -2.2e-170) tmp = y * z; elseif (z <= 1.0) tmp = x; elseif (z <= 1.15e+171) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.7e+53], t$95$0, If[LessEqual[z, -5.2e-60], N[(y * z), $MachinePrecision], If[LessEqual[z, -5.8e-164], x, If[LessEqual[z, -2.2e-170], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, If[LessEqual[z, 1.15e+171], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.7 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -5.2 \cdot 10^{-60}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{-164}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{-170}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.69999999999999999e53 or 1 < z < 1.15000000000000009e171Initial program 99.9%
Taylor expanded in z around inf 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around inf 98.7%
mul-1-neg98.7%
Simplified98.7%
Taylor expanded in y around 0 63.3%
associate-*r*63.3%
mul-1-neg63.3%
Simplified63.3%
if -1.69999999999999999e53 < z < -5.1999999999999995e-60 or -5.8e-164 < z < -2.20000000000000015e-170 or 1.15000000000000009e171 < z Initial program 99.9%
Taylor expanded in y around inf 75.1%
*-commutative75.1%
Simplified75.1%
Taylor expanded in y around inf 73.4%
Taylor expanded in y around inf 69.2%
if -5.1999999999999995e-60 < z < -5.8e-164 or -2.20000000000000015e-170 < z < 1Initial program 100.0%
Taylor expanded in z around 0 70.8%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = (y - 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 ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = (y - 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 ((z <= -1.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 99.9%
Taylor expanded in z around inf 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in z around inf 98.5%
mul-1-neg98.5%
Simplified98.5%
Taylor expanded in z around 0 98.5%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -840.0) (not (<= x 7.2e-13))) (* x (- 1.0 z)) (* (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -840.0) || !(x <= 7.2e-13)) {
tmp = x * (1.0 - z);
} else {
tmp = (y - 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 ((x <= (-840.0d0)) .or. (.not. (x <= 7.2d-13))) then
tmp = x * (1.0d0 - z)
else
tmp = (y - x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -840.0) || !(x <= 7.2e-13)) {
tmp = x * (1.0 - z);
} else {
tmp = (y - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -840.0) or not (x <= 7.2e-13): tmp = x * (1.0 - z) else: tmp = (y - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -840.0) || !(x <= 7.2e-13)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(Float64(y - x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -840.0) || ~((x <= 7.2e-13))) tmp = x * (1.0 - z); else tmp = (y - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -840.0], N[Not[LessEqual[x, 7.2e-13]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -840 \lor \neg \left(x \leq 7.2 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - x\right) \cdot z\\
\end{array}
\end{array}
if x < -840 or 7.1999999999999996e-13 < x Initial program 99.9%
Taylor expanded in x around inf 89.8%
mul-1-neg89.8%
unsub-neg89.8%
Simplified89.8%
if -840 < x < 7.1999999999999996e-13Initial program 99.9%
Taylor expanded in z around inf 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around inf 83.5%
mul-1-neg83.5%
Simplified83.5%
Taylor expanded in z around 0 83.5%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (<= x -60000.0) x (if (<= x 5.2e-13) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -60000.0) {
tmp = x;
} else if (x <= 5.2e-13) {
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 (x <= (-60000.0d0)) then
tmp = x
else if (x <= 5.2d-13) 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 (x <= -60000.0) {
tmp = x;
} else if (x <= 5.2e-13) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -60000.0: tmp = x elif x <= 5.2e-13: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -60000.0) tmp = x; elseif (x <= 5.2e-13) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -60000.0) tmp = x; elseif (x <= 5.2e-13) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -60000.0], x, If[LessEqual[x, 5.2e-13], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -60000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-13}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -6e4 or 5.2000000000000001e-13 < x Initial program 99.9%
Taylor expanded in z around 0 50.7%
if -6e4 < x < 5.2000000000000001e-13Initial program 99.9%
Taylor expanded in y around inf 82.7%
*-commutative82.7%
Simplified82.7%
Taylor expanded in y around inf 82.6%
Taylor expanded in y around inf 67.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 99.9%
(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 99.9%
Taylor expanded in z around 0 33.7%
herbie shell --seed 2024088
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))