
(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-define100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= z -7.6e-69) (* y z) (if (<= z 0.0115) x (if (<= z 8e+264) (* x (- z)) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e-69) {
tmp = y * z;
} else if (z <= 0.0115) {
tmp = x;
} else if (z <= 8e+264) {
tmp = x * -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 (z <= (-7.6d-69)) then
tmp = y * z
else if (z <= 0.0115d0) then
tmp = x
else if (z <= 8d+264) then
tmp = x * -z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e-69) {
tmp = y * z;
} else if (z <= 0.0115) {
tmp = x;
} else if (z <= 8e+264) {
tmp = x * -z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.6e-69: tmp = y * z elif z <= 0.0115: tmp = x elif z <= 8e+264: tmp = x * -z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.6e-69) tmp = Float64(y * z); elseif (z <= 0.0115) tmp = x; elseif (z <= 8e+264) tmp = Float64(x * Float64(-z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.6e-69) tmp = y * z; elseif (z <= 0.0115) tmp = x; elseif (z <= 8e+264) tmp = x * -z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.6e-69], N[(y * z), $MachinePrecision], If[LessEqual[z, 0.0115], x, If[LessEqual[z, 8e+264], N[(x * (-z)), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{-69}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 0.0115:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+264}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -7.5999999999999995e-69 or 8.00000000000000035e264 < z Initial program 100.0%
Taylor expanded in y around inf 64.8%
*-commutative64.8%
Simplified64.8%
Taylor expanded in z around inf 63.9%
Taylor expanded in y around inf 61.0%
if -7.5999999999999995e-69 < z < 0.0115Initial program 100.0%
Taylor expanded in z around 0 74.2%
if 0.0115 < z < 8.00000000000000035e264Initial program 99.9%
Taylor expanded in x around inf 60.6%
mul-1-neg60.6%
unsub-neg60.6%
Simplified60.6%
Taylor expanded in z around inf 59.8%
neg-mul-159.8%
Simplified59.8%
Final simplification66.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e+63) (not (<= x 4.9e+76))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+63) || !(x <= 4.9e+76)) {
tmp = x * (1.0 - 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 <= (-2.6d+63)) .or. (.not. (x <= 4.9d+76))) then
tmp = x * (1.0d0 - 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 <= -2.6e+63) || !(x <= 4.9e+76)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e+63) or not (x <= 4.9e+76): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e+63) || !(x <= 4.9e+76)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.6e+63) || ~((x <= 4.9e+76))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e+63], N[Not[LessEqual[x, 4.9e+76]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+63} \lor \neg \left(x \leq 4.9 \cdot 10^{+76}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.6000000000000001e63 or 4.90000000000000026e76 < x Initial program 100.0%
Taylor expanded in x around inf 93.3%
mul-1-neg93.3%
unsub-neg93.3%
Simplified93.3%
if -2.6000000000000001e63 < x < 4.90000000000000026e76Initial program 99.9%
Taylor expanded in y around inf 89.0%
*-commutative89.0%
Simplified89.0%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e-10) (not (<= x 2.05e-18))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-10) || !(x <= 2.05e-18)) {
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 <= (-2.1d-10)) .or. (.not. (x <= 2.05d-18))) 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 <= -2.1e-10) || !(x <= 2.05e-18)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e-10) or not (x <= 2.05e-18): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e-10) || !(x <= 2.05e-18)) 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 <= -2.1e-10) || ~((x <= 2.05e-18))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e-10], N[Not[LessEqual[x, 2.05e-18]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-10} \lor \neg \left(x \leq 2.05 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.1e-10 or 2.0499999999999999e-18 < x Initial program 100.0%
Taylor expanded in x around inf 86.6%
mul-1-neg86.6%
unsub-neg86.6%
Simplified86.6%
if -2.1e-10 < x < 2.0499999999999999e-18Initial program 99.9%
Taylor expanded in y around inf 91.5%
*-commutative91.5%
Simplified91.5%
Taylor expanded in z around inf 91.5%
Taylor expanded in y around inf 74.7%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e-68) (not (<= z 1.08e-13))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-68) || !(z <= 1.08e-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 ((z <= (-1.15d-68)) .or. (.not. (z <= 1.08d-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 ((z <= -1.15e-68) || !(z <= 1.08e-13)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e-68) or not (z <= 1.08e-13): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e-68) || !(z <= 1.08e-13)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e-68) || ~((z <= 1.08e-13))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e-68], N[Not[LessEqual[z, 1.08e-13]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-68} \lor \neg \left(z \leq 1.08 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.14999999999999998e-68 or 1.0799999999999999e-13 < z Initial program 100.0%
Taylor expanded in y around inf 57.3%
*-commutative57.3%
Simplified57.3%
Taylor expanded in z around inf 56.7%
Taylor expanded in y around inf 55.2%
if -1.14999999999999998e-68 < z < 1.0799999999999999e-13Initial program 100.0%
Taylor expanded in z around 0 74.2%
Final simplification62.9%
(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%
(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 32.4%
herbie shell --seed 2024181
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))