
(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 7 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 -8e+183)
(* y z)
(if (<= z -4.4e+17)
t_0
(if (<= z -3.2e-111)
(* y z)
(if (<= z 2.4e-14)
x
(if (or (<= z 7.2e+19)
(not
(or (<= z 1.6e+74)
(and (not (<= z 1.65e+214)) (<= z 1.12e+253)))))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -8e+183) {
tmp = y * z;
} else if (z <= -4.4e+17) {
tmp = t_0;
} else if (z <= -3.2e-111) {
tmp = y * z;
} else if (z <= 2.4e-14) {
tmp = x;
} else if ((z <= 7.2e+19) || !((z <= 1.6e+74) || (!(z <= 1.65e+214) && (z <= 1.12e+253)))) {
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+183)) then
tmp = y * z
else if (z <= (-4.4d+17)) then
tmp = t_0
else if (z <= (-3.2d-111)) then
tmp = y * z
else if (z <= 2.4d-14) then
tmp = x
else if ((z <= 7.2d+19) .or. (.not. (z <= 1.6d+74) .or. (.not. (z <= 1.65d+214)) .and. (z <= 1.12d+253))) 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+183) {
tmp = y * z;
} else if (z <= -4.4e+17) {
tmp = t_0;
} else if (z <= -3.2e-111) {
tmp = y * z;
} else if (z <= 2.4e-14) {
tmp = x;
} else if ((z <= 7.2e+19) || !((z <= 1.6e+74) || (!(z <= 1.65e+214) && (z <= 1.12e+253)))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -8e+183: tmp = y * z elif z <= -4.4e+17: tmp = t_0 elif z <= -3.2e-111: tmp = y * z elif z <= 2.4e-14: tmp = x elif (z <= 7.2e+19) or not ((z <= 1.6e+74) or (not (z <= 1.65e+214) and (z <= 1.12e+253))): 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+183) tmp = Float64(y * z); elseif (z <= -4.4e+17) tmp = t_0; elseif (z <= -3.2e-111) tmp = Float64(y * z); elseif (z <= 2.4e-14) tmp = x; elseif ((z <= 7.2e+19) || !((z <= 1.6e+74) || (!(z <= 1.65e+214) && (z <= 1.12e+253)))) 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+183) tmp = y * z; elseif (z <= -4.4e+17) tmp = t_0; elseif (z <= -3.2e-111) tmp = y * z; elseif (z <= 2.4e-14) tmp = x; elseif ((z <= 7.2e+19) || ~(((z <= 1.6e+74) || (~((z <= 1.65e+214)) && (z <= 1.12e+253))))) 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+183], N[(y * z), $MachinePrecision], If[LessEqual[z, -4.4e+17], t$95$0, If[LessEqual[z, -3.2e-111], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.4e-14], x, If[Or[LessEqual[z, 7.2e+19], N[Not[Or[LessEqual[z, 1.6e+74], And[N[Not[LessEqual[z, 1.65e+214]], $MachinePrecision], LessEqual[z, 1.12e+253]]]], $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 -8 \cdot 10^{+183}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{+17}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-111}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{+19} \lor \neg \left(z \leq 1.6 \cdot 10^{+74} \lor \neg \left(z \leq 1.65 \cdot 10^{+214}\right) \land z \leq 1.12 \cdot 10^{+253}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.5e+134)
(and (not (<= y -2.16e+52))
(or (<= y -1.85e+14) (not (<= y 2.5e+34)))))
(* y z)
(* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e+134) || (!(y <= -2.16e+52) && ((y <= -1.85e+14) || !(y <= 2.5e+34)))) {
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 <= (-1.5d+134)) .or. (.not. (y <= (-2.16d+52))) .and. (y <= (-1.85d+14)) .or. (.not. (y <= 2.5d+34))) 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 <= -1.5e+134) || (!(y <= -2.16e+52) && ((y <= -1.85e+14) || !(y <= 2.5e+34)))) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e+134) or (not (y <= -2.16e+52) and ((y <= -1.85e+14) or not (y <= 2.5e+34))): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e+134) || (!(y <= -2.16e+52) && ((y <= -1.85e+14) || !(y <= 2.5e+34)))) 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 <= -1.5e+134) || (~((y <= -2.16e+52)) && ((y <= -1.85e+14) || ~((y <= 2.5e+34))))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e+134], And[N[Not[LessEqual[y, -2.16e+52]], $MachinePrecision], Or[LessEqual[y, -1.85e+14], N[Not[LessEqual[y, 2.5e+34]], $MachinePrecision]]]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+134} \lor \neg \left(y \leq -2.16 \cdot 10^{+52}\right) \land \left(y \leq -1.85 \cdot 10^{+14} \lor \neg \left(y \leq 2.5 \cdot 10^{+34}\right)\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -5.6e-29) (not (<= y 1.25e+34))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.6e-29) || !(y <= 1.25e+34)) {
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 <= (-5.6d-29)) .or. (.not. (y <= 1.25d+34))) 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 <= -5.6e-29) || !(y <= 1.25e+34)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.6e-29) or not (y <= 1.25e+34): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.6e-29) || !(y <= 1.25e+34)) 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 <= -5.6e-29) || ~((y <= 1.25e+34))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.6e-29], N[Not[LessEqual[y, 1.25e+34]], $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 -5.6 \cdot 10^{-29} \lor \neg \left(y \leq 1.25 \cdot 10^{+34}\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 (<= z -3.2e-111) (not (<= z 6.4e-15))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e-111) || !(z <= 6.4e-15)) {
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 <= (-3.2d-111)) .or. (.not. (z <= 6.4d-15))) 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 <= -3.2e-111) || !(z <= 6.4e-15)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e-111) or not (z <= 6.4e-15): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e-111) || !(z <= 6.4e-15)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e-111) || ~((z <= 6.4e-15))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e-111], N[Not[LessEqual[z, 6.4e-15]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{-111} \lor \neg \left(z \leq 6.4 \cdot 10^{-15}\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 2023350
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))