
(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 8 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 -2.3e-7) (* y z) (if (<= z 1.68e-15) x (if (<= z 3.6e+217) (* y z) (* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e-7) {
tmp = y * z;
} else if (z <= 1.68e-15) {
tmp = x;
} else if (z <= 3.6e+217) {
tmp = y * z;
} else {
tmp = x * -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 <= (-2.3d-7)) then
tmp = y * z
else if (z <= 1.68d-15) then
tmp = x
else if (z <= 3.6d+217) then
tmp = y * z
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e-7) {
tmp = y * z;
} else if (z <= 1.68e-15) {
tmp = x;
} else if (z <= 3.6e+217) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.3e-7: tmp = y * z elif z <= 1.68e-15: tmp = x elif z <= 3.6e+217: tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.3e-7) tmp = Float64(y * z); elseif (z <= 1.68e-15) tmp = x; elseif (z <= 3.6e+217) tmp = Float64(y * z); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.3e-7) tmp = y * z; elseif (z <= 1.68e-15) tmp = x; elseif (z <= 3.6e+217) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.3e-7], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.68e-15], x, If[LessEqual[z, 3.6e+217], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.68 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+217}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -2.29999999999999995e-7 or 1.6800000000000001e-15 < z < 3.6000000000000002e217Initial program 99.9%
Taylor expanded in y around inf 59.1%
*-commutative59.1%
Simplified59.1%
Taylor expanded in y around inf 62.8%
Taylor expanded in z around inf 58.6%
if -2.29999999999999995e-7 < z < 1.6800000000000001e-15Initial program 100.0%
Taylor expanded in z around 0 73.7%
if 3.6000000000000002e217 < z Initial program 100.0%
Taylor expanded in x around inf 70.3%
mul-1-neg70.3%
unsub-neg70.3%
Simplified70.3%
Taylor expanded in z around inf 70.3%
neg-mul-170.3%
Simplified70.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.85e-82) (+ x (* y z)) (if (<= y 1.4e-63) (* x (- 1.0 z)) (* y (+ z (/ x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-82) {
tmp = x + (y * z);
} else if (y <= 1.4e-63) {
tmp = x * (1.0 - z);
} else {
tmp = y * (z + (x / y));
}
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.85d-82)) then
tmp = x + (y * z)
else if (y <= 1.4d-63) then
tmp = x * (1.0d0 - z)
else
tmp = y * (z + (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-82) {
tmp = x + (y * z);
} else if (y <= 1.4e-63) {
tmp = x * (1.0 - z);
} else {
tmp = y * (z + (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e-82: tmp = x + (y * z) elif y <= 1.4e-63: tmp = x * (1.0 - z) else: tmp = y * (z + (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e-82) tmp = Float64(x + Float64(y * z)); elseif (y <= 1.4e-63) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * Float64(z + Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.85e-82) tmp = x + (y * z); elseif (y <= 1.4e-63) tmp = x * (1.0 - z); else tmp = y * (z + (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e-82], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-63], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{-82}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-63}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < -1.85e-82Initial program 100.0%
Taylor expanded in y around inf 91.9%
*-commutative91.9%
Simplified91.9%
if -1.85e-82 < y < 1.4000000000000001e-63Initial program 99.9%
Taylor expanded in x around inf 85.9%
mul-1-neg85.9%
unsub-neg85.9%
Simplified85.9%
if 1.4000000000000001e-63 < y Initial program 100.0%
Taylor expanded in y around inf 90.1%
*-commutative90.1%
Simplified90.1%
Taylor expanded in y around inf 90.1%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.6e-89) (not (<= y 8e-64))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.6e-89) || !(y <= 8e-64)) {
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-89)) .or. (.not. (y <= 8d-64))) 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-89) || !(y <= 8e-64)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.6e-89) or not (y <= 8e-64): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.6e-89) || !(y <= 8e-64)) 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-89) || ~((y <= 8e-64))) 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-89], N[Not[LessEqual[y, 8e-64]], $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^{-89} \lor \neg \left(y \leq 8 \cdot 10^{-64}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.5999999999999998e-89 or 7.99999999999999972e-64 < y Initial program 100.0%
Taylor expanded in y around inf 91.0%
*-commutative91.0%
Simplified91.0%
if -5.5999999999999998e-89 < y < 7.99999999999999972e-64Initial program 99.9%
Taylor expanded in x around inf 85.9%
mul-1-neg85.9%
unsub-neg85.9%
Simplified85.9%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e-38) (not (<= x 6.5e-138))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-38) || !(x <= 6.5e-138)) {
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.3d-38)) .or. (.not. (x <= 6.5d-138))) 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.3e-38) || !(x <= 6.5e-138)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e-38) or not (x <= 6.5e-138): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e-38) || !(x <= 6.5e-138)) 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.3e-38) || ~((x <= 6.5e-138))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e-38], N[Not[LessEqual[x, 6.5e-138]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-38} \lor \neg \left(x \leq 6.5 \cdot 10^{-138}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.30000000000000005e-38 or 6.4999999999999999e-138 < x Initial program 100.0%
Taylor expanded in x around inf 80.1%
mul-1-neg80.1%
unsub-neg80.1%
Simplified80.1%
if -1.30000000000000005e-38 < x < 6.4999999999999999e-138Initial program 99.9%
Taylor expanded in y around inf 89.4%
*-commutative89.4%
Simplified89.4%
Taylor expanded in y around inf 89.4%
Taylor expanded in z around inf 75.6%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e-7) (not (<= z 1.42e-13))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e-7) || !(z <= 1.42e-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 <= (-2.2d-7)) .or. (.not. (z <= 1.42d-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 <= -2.2e-7) || !(z <= 1.42e-13)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e-7) or not (z <= 1.42e-13): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e-7) || !(z <= 1.42e-13)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.2e-7) || ~((z <= 1.42e-13))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e-7], N[Not[LessEqual[z, 1.42e-13]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-7} \lor \neg \left(z \leq 1.42 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2000000000000001e-7 or 1.42e-13 < z Initial program 99.9%
Taylor expanded in y around inf 55.9%
*-commutative55.9%
Simplified55.9%
Taylor expanded in y around inf 59.2%
Taylor expanded in z around inf 55.5%
if -2.2000000000000001e-7 < z < 1.42e-13Initial program 100.0%
Taylor expanded in z around 0 73.7%
Final simplification63.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 35.2%
herbie shell --seed 2024191
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))