
(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 (or (<= x -1.6e+126) (not (<= x 5.5e+46))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+126) || !(x <= 5.5e+46)) {
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 <= (-1.6d+126)) .or. (.not. (x <= 5.5d+46))) 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 <= -1.6e+126) || !(x <= 5.5e+46)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+126) or not (x <= 5.5e+46): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+126) || !(x <= 5.5e+46)) 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 <= -1.6e+126) || ~((x <= 5.5e+46))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+126], N[Not[LessEqual[x, 5.5e+46]], $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 -1.6 \cdot 10^{+126} \lor \neg \left(x \leq 5.5 \cdot 10^{+46}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.5999999999999999e126 or 5.4999999999999998e46 < x Initial program 100.0%
Taylor expanded in x around inf 93.6%
mul-1-neg93.6%
unsub-neg93.6%
Simplified93.6%
if -1.5999999999999999e126 < x < 5.4999999999999998e46Initial program 100.0%
Taylor expanded in y around inf 86.3%
*-commutative86.3%
Simplified86.3%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.95e-37) (not (<= x 2.55e+39))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.95e-37) || !(x <= 2.55e+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 <= (-2.95d-37)) .or. (.not. (x <= 2.55d+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 <= -2.95e-37) || !(x <= 2.55e+39)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.95e-37) or not (x <= 2.55e+39): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.95e-37) || !(x <= 2.55e+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 <= -2.95e-37) || ~((x <= 2.55e+39))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.95e-37], N[Not[LessEqual[x, 2.55e+39]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.95 \cdot 10^{-37} \lor \neg \left(x \leq 2.55 \cdot 10^{+39}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.9499999999999998e-37 or 2.5499999999999999e39 < x Initial program 100.0%
Taylor expanded in x around inf 86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
if -2.9499999999999998e-37 < x < 2.5499999999999999e39Initial program 100.0%
Taylor expanded in y around inf 90.1%
*-commutative90.1%
Simplified90.1%
Taylor expanded in y around inf 90.1%
Taylor expanded in y around inf 68.3%
*-commutative68.3%
Simplified68.3%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (<= x -1.6e+126) (- x (* x z)) (if (<= x 2.7e+46) (+ x (* y z)) (* x (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+126) {
tmp = x - (x * z);
} else if (x <= 2.7e+46) {
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 (x <= (-1.6d+126)) then
tmp = x - (x * z)
else if (x <= 2.7d+46) 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 (x <= -1.6e+126) {
tmp = x - (x * z);
} else if (x <= 2.7e+46) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e+126: tmp = x - (x * z) elif x <= 2.7e+46: tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e+126) tmp = Float64(x - Float64(x * z)); elseif (x <= 2.7e+46) 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 (x <= -1.6e+126) tmp = x - (x * z); elseif (x <= 2.7e+46) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e+126], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.7e+46], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+126}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+46}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if x < -1.5999999999999999e126Initial program 100.0%
Taylor expanded in x around inf 97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
sub-neg97.2%
distribute-rgt-in97.2%
*-un-lft-identity97.2%
distribute-lft-neg-in97.2%
unsub-neg97.2%
Applied egg-rr97.2%
if -1.5999999999999999e126 < x < 2.7000000000000002e46Initial program 100.0%
Taylor expanded in y around inf 86.3%
*-commutative86.3%
Simplified86.3%
if 2.7000000000000002e46 < x Initial program 100.0%
Taylor expanded in x around inf 91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -6e-45) (not (<= z 0.000135))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e-45) || !(z <= 0.000135)) {
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 <= (-6d-45)) .or. (.not. (z <= 0.000135d0))) 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 <= -6e-45) || !(z <= 0.000135)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e-45) or not (z <= 0.000135): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e-45) || !(z <= 0.000135)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6e-45) || ~((z <= 0.000135))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e-45], N[Not[LessEqual[z, 0.000135]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-45} \lor \neg \left(z \leq 0.000135\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.00000000000000022e-45 or 1.35000000000000002e-4 < z Initial program 100.0%
Taylor expanded in y around inf 59.9%
*-commutative59.9%
Simplified59.9%
Taylor expanded in y around inf 62.5%
Taylor expanded in y around inf 57.4%
*-commutative57.4%
Simplified57.4%
if -6.00000000000000022e-45 < z < 1.35000000000000002e-4Initial program 100.0%
Taylor expanded in z around 0 69.5%
Final simplification62.8%
(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 33.7%
herbie shell --seed 2024149
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))