
(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}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -3.8e+105)
(* y z)
(if (<= z -2800000.0)
t_0
(if (<= z 2.3e-15)
x
(if (or (<= z 6.6e+215) (not (<= z 3.1e+243))) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.8e+105) {
tmp = y * z;
} else if (z <= -2800000.0) {
tmp = t_0;
} else if (z <= 2.3e-15) {
tmp = x;
} else if ((z <= 6.6e+215) || !(z <= 3.1e+243)) {
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 <= (-3.8d+105)) then
tmp = y * z
else if (z <= (-2800000.0d0)) then
tmp = t_0
else if (z <= 2.3d-15) then
tmp = x
else if ((z <= 6.6d+215) .or. (.not. (z <= 3.1d+243))) 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 <= -3.8e+105) {
tmp = y * z;
} else if (z <= -2800000.0) {
tmp = t_0;
} else if (z <= 2.3e-15) {
tmp = x;
} else if ((z <= 6.6e+215) || !(z <= 3.1e+243)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3.8e+105: tmp = y * z elif z <= -2800000.0: tmp = t_0 elif z <= 2.3e-15: tmp = x elif (z <= 6.6e+215) or not (z <= 3.1e+243): 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 <= -3.8e+105) tmp = Float64(y * z); elseif (z <= -2800000.0) tmp = t_0; elseif (z <= 2.3e-15) tmp = x; elseif ((z <= 6.6e+215) || !(z <= 3.1e+243)) 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 <= -3.8e+105) tmp = y * z; elseif (z <= -2800000.0) tmp = t_0; elseif (z <= 2.3e-15) tmp = x; elseif ((z <= 6.6e+215) || ~((z <= 3.1e+243))) 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, -3.8e+105], N[(y * z), $MachinePrecision], If[LessEqual[z, -2800000.0], t$95$0, If[LessEqual[z, 2.3e-15], x, If[Or[LessEqual[z, 6.6e+215], N[Not[LessEqual[z, 3.1e+243]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{+105}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2800000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{+215} \lor \neg \left(z \leq 3.1 \cdot 10^{+243}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -6.3e+63) (not (<= x 2.3e-102))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.3e+63) || !(x <= 2.3e-102)) {
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 <= (-6.3d+63)) .or. (.not. (x <= 2.3d-102))) 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 <= -6.3e+63) || !(x <= 2.3e-102)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.3e+63) or not (x <= 2.3e-102): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.3e+63) || !(x <= 2.3e-102)) 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 <= -6.3e+63) || ~((x <= 2.3e-102))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.3e+63], N[Not[LessEqual[x, 2.3e-102]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.3 \cdot 10^{+63} \lor \neg \left(x \leq 2.3 \cdot 10^{-102}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -3.1e-91) (not (<= y 3.35e-62))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1e-91) || !(y <= 3.35e-62)) {
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 ((y <= (-3.1d-91)) .or. (.not. (y <= 3.35d-62))) 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 ((y <= -3.1e-91) || !(y <= 3.35e-62)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.1e-91) or not (y <= 3.35e-62): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.1e-91) || !(y <= 3.35e-62)) 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 ((y <= -3.1e-91) || ~((y <= 3.35e-62))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.1e-91], N[Not[LessEqual[y, 3.35e-62]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{-91} \lor \neg \left(y \leq 3.35 \cdot 10^{-62}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -9e-90) (not (<= y 3.8e-62))) (+ x (* y z)) (- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-90) || !(y <= 3.8e-62)) {
tmp = x + (y * z);
} else {
tmp = x - (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 ((y <= (-9d-90)) .or. (.not. (y <= 3.8d-62))) then
tmp = x + (y * z)
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-90) || !(y <= 3.8e-62)) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e-90) or not (y <= 3.8e-62): tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e-90) || !(y <= 3.8e-62)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9e-90) || ~((y <= 3.8e-62))) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e-90], N[Not[LessEqual[y, 3.8e-62]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-90} \lor \neg \left(y \leq 3.8 \cdot 10^{-62}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -1.58e-28) (not (<= z 7.8e-16))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.58e-28) || !(z <= 7.8e-16)) {
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.58d-28)) .or. (.not. (z <= 7.8d-16))) 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.58e-28) || !(z <= 7.8e-16)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.58e-28) or not (z <= 7.8e-16): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.58e-28) || !(z <= 7.8e-16)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.58e-28) || ~((z <= 7.8e-16))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.58e-28], N[Not[LessEqual[z, 7.8e-16]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.58 \cdot 10^{-28} \lor \neg \left(z \leq 7.8 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(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 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}
herbie shell --seed 2024003
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))