
(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 6 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 (+ 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
(let* ((t_0 (* x (- z))))
(if (<= z -3e+256)
t_0
(if (<= z -1.65e+227)
(* y z)
(if (<= z -6.2e+189)
t_0
(if (<= z -3.2)
(* y z)
(if (<= z 5.1e-20)
x
(if (or (<= z 6e+43)
(not
(or (<= z 3.75e+121)
(and (not (<= z 2.6e+214)) (<= z 4.8e+241)))))
(* y z)
t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3e+256) {
tmp = t_0;
} else if (z <= -1.65e+227) {
tmp = y * z;
} else if (z <= -6.2e+189) {
tmp = t_0;
} else if (z <= -3.2) {
tmp = y * z;
} else if (z <= 5.1e-20) {
tmp = x;
} else if ((z <= 6e+43) || !((z <= 3.75e+121) || (!(z <= 2.6e+214) && (z <= 4.8e+241)))) {
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 <= (-3d+256)) then
tmp = t_0
else if (z <= (-1.65d+227)) then
tmp = y * z
else if (z <= (-6.2d+189)) then
tmp = t_0
else if (z <= (-3.2d0)) then
tmp = y * z
else if (z <= 5.1d-20) then
tmp = x
else if ((z <= 6d+43) .or. (.not. (z <= 3.75d+121) .or. (.not. (z <= 2.6d+214)) .and. (z <= 4.8d+241))) 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 <= -3e+256) {
tmp = t_0;
} else if (z <= -1.65e+227) {
tmp = y * z;
} else if (z <= -6.2e+189) {
tmp = t_0;
} else if (z <= -3.2) {
tmp = y * z;
} else if (z <= 5.1e-20) {
tmp = x;
} else if ((z <= 6e+43) || !((z <= 3.75e+121) || (!(z <= 2.6e+214) && (z <= 4.8e+241)))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3e+256: tmp = t_0 elif z <= -1.65e+227: tmp = y * z elif z <= -6.2e+189: tmp = t_0 elif z <= -3.2: tmp = y * z elif z <= 5.1e-20: tmp = x elif (z <= 6e+43) or not ((z <= 3.75e+121) or (not (z <= 2.6e+214) and (z <= 4.8e+241))): 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 <= -3e+256) tmp = t_0; elseif (z <= -1.65e+227) tmp = Float64(y * z); elseif (z <= -6.2e+189) tmp = t_0; elseif (z <= -3.2) tmp = Float64(y * z); elseif (z <= 5.1e-20) tmp = x; elseif ((z <= 6e+43) || !((z <= 3.75e+121) || (!(z <= 2.6e+214) && (z <= 4.8e+241)))) 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 <= -3e+256) tmp = t_0; elseif (z <= -1.65e+227) tmp = y * z; elseif (z <= -6.2e+189) tmp = t_0; elseif (z <= -3.2) tmp = y * z; elseif (z <= 5.1e-20) tmp = x; elseif ((z <= 6e+43) || ~(((z <= 3.75e+121) || (~((z <= 2.6e+214)) && (z <= 4.8e+241))))) 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, -3e+256], t$95$0, If[LessEqual[z, -1.65e+227], N[(y * z), $MachinePrecision], If[LessEqual[z, -6.2e+189], t$95$0, If[LessEqual[z, -3.2], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.1e-20], x, If[Or[LessEqual[z, 6e+43], N[Not[Or[LessEqual[z, 3.75e+121], And[N[Not[LessEqual[z, 2.6e+214]], $MachinePrecision], LessEqual[z, 4.8e+241]]]], $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 \cdot 10^{+256}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.65 \cdot 10^{+227}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -6.2 \cdot 10^{+189}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.2:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.1 \cdot 10^{-20}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+43} \lor \neg \left(z \leq 3.75 \cdot 10^{+121} \lor \neg \left(z \leq 2.6 \cdot 10^{+214}\right) \land z \leq 4.8 \cdot 10^{+241}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e+83) (not (<= x 7.8e-82))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+83) || !(x <= 7.8e-82)) {
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 <= (-5.5d+83)) .or. (.not. (x <= 7.8d-82))) 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 <= -5.5e+83) || !(x <= 7.8e-82)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e+83) or not (x <= 7.8e-82): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+83) || !(x <= 7.8e-82)) 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 <= -5.5e+83) || ~((x <= 7.8e-82))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+83], N[Not[LessEqual[x, 7.8e-82]], $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 -5.5 \cdot 10^{+83} \lor \neg \left(x \leq 7.8 \cdot 10^{-82}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2) (not (<= z 3.2e-21))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2) || !(z <= 3.2e-21)) {
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.2d0)) .or. (.not. (z <= 3.2d-21))) 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.2) || !(z <= 3.2e-21)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2) or not (z <= 3.2e-21): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2) || !(z <= 3.2e-21)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2) || ~((z <= 3.2e-21))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2], N[Not[LessEqual[z, 3.2e-21]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \lor \neg \left(z \leq 3.2 \cdot 10^{-21}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (y * 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 * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \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 2023343
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))