
(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}
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 -3.3e+25)
t_0
(if (<= z -2.85e-87)
(* y z)
(if (<= z 4.3e-33)
x
(if (or (<= z 9600.0) (not (<= z 1.35e+83))) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.3e+25) {
tmp = t_0;
} else if (z <= -2.85e-87) {
tmp = y * z;
} else if (z <= 4.3e-33) {
tmp = x;
} else if ((z <= 9600.0) || !(z <= 1.35e+83)) {
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.3d+25)) then
tmp = t_0
else if (z <= (-2.85d-87)) then
tmp = y * z
else if (z <= 4.3d-33) then
tmp = x
else if ((z <= 9600.0d0) .or. (.not. (z <= 1.35d+83))) 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.3e+25) {
tmp = t_0;
} else if (z <= -2.85e-87) {
tmp = y * z;
} else if (z <= 4.3e-33) {
tmp = x;
} else if ((z <= 9600.0) || !(z <= 1.35e+83)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3.3e+25: tmp = t_0 elif z <= -2.85e-87: tmp = y * z elif z <= 4.3e-33: tmp = x elif (z <= 9600.0) or not (z <= 1.35e+83): 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.3e+25) tmp = t_0; elseif (z <= -2.85e-87) tmp = Float64(y * z); elseif (z <= 4.3e-33) tmp = x; elseif ((z <= 9600.0) || !(z <= 1.35e+83)) 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.3e+25) tmp = t_0; elseif (z <= -2.85e-87) tmp = y * z; elseif (z <= 4.3e-33) tmp = x; elseif ((z <= 9600.0) || ~((z <= 1.35e+83))) 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.3e+25], t$95$0, If[LessEqual[z, -2.85e-87], N[(y * z), $MachinePrecision], If[LessEqual[z, 4.3e-33], x, If[Or[LessEqual[z, 9600.0], N[Not[LessEqual[z, 1.35e+83]], $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.3 \cdot 10^{+25}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.85 \cdot 10^{-87}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-33}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9600 \lor \neg \left(z \leq 1.35 \cdot 10^{+83}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.3000000000000001e25 or 9600 < z < 1.35000000000000003e83Initial program 100.0%
Taylor expanded in x around inf 63.1%
mul-1-neg63.1%
unsub-neg63.1%
Simplified63.1%
Taylor expanded in z around inf 61.4%
mul-1-neg61.4%
distribute-rgt-neg-out61.4%
Simplified61.4%
if -3.3000000000000001e25 < z < -2.85e-87 or 4.30000000000000031e-33 < z < 9600 or 1.35000000000000003e83 < z Initial program 100.0%
Taylor expanded in x around 0 64.0%
if -2.85e-87 < z < 4.30000000000000031e-33Initial program 100.0%
Taylor expanded in z around 0 80.6%
Final simplification69.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-128) (not (<= x 1e+39))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-128) || !(x <= 1e+39)) {
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.2d-128)) .or. (.not. (x <= 1d+39))) 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.2e-128) || !(x <= 1e+39)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-128) or not (x <= 1e+39): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-128) || !(x <= 1e+39)) 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.2e-128) || ~((x <= 1e+39))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-128], N[Not[LessEqual[x, 1e+39]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-128} \lor \neg \left(x \leq 10^{+39}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.1999999999999999e-128 or 9.9999999999999994e38 < x Initial program 100.0%
Taylor expanded in x around inf 86.4%
mul-1-neg86.4%
unsub-neg86.4%
Simplified86.4%
if -1.1999999999999999e-128 < x < 9.9999999999999994e38Initial program 100.0%
Taylor expanded in x around 0 73.6%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-90) (not (<= z 9.5e-34))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-90) || !(z <= 9.5e-34)) {
tmp = (y - x) * 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 <= (-4.8d-90)) .or. (.not. (z <= 9.5d-34))) then
tmp = (y - x) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-90) || !(z <= 9.5e-34)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e-90) or not (z <= 9.5e-34): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e-90) || !(z <= 9.5e-34)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.8e-90) || ~((z <= 9.5e-34))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-90], N[Not[LessEqual[z, 9.5e-34]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-90} \lor \neg \left(z \leq 9.5 \cdot 10^{-34}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.8000000000000003e-90 or 9.49999999999999985e-34 < z Initial program 100.0%
Taylor expanded in z around inf 93.5%
if -4.8000000000000003e-90 < z < 9.49999999999999985e-34Initial program 100.0%
Taylor expanded in z around 0 81.1%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.86e-87) (not (<= z 1.35e-33))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.86e-87) || !(z <= 1.35e-33)) {
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.86d-87)) .or. (.not. (z <= 1.35d-33))) 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.86e-87) || !(z <= 1.35e-33)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.86e-87) or not (z <= 1.35e-33): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.86e-87) || !(z <= 1.35e-33)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.86e-87) || ~((z <= 1.35e-33))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.86e-87], N[Not[LessEqual[z, 1.35e-33]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.86 \cdot 10^{-87} \lor \neg \left(z \leq 1.35 \cdot 10^{-33}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.8600000000000001e-87 or 1.35e-33 < z Initial program 100.0%
Taylor expanded in x around 0 54.0%
if -1.8600000000000001e-87 < z < 1.35e-33Initial program 100.0%
Taylor expanded in z around 0 80.6%
Final simplification64.5%
(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 35.9%
Final simplification35.9%
herbie shell --seed 2024018
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))