
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -3.1e+171)
(* y z)
(if (<= z -5.2e+26)
t_0
(if (<= z -9.5e-22) (* y z) (if (<= z 1.0) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.1e+171) {
tmp = y * z;
} else if (z <= -5.2e+26) {
tmp = t_0;
} else if (z <= -9.5e-22) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} 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.1d+171)) then
tmp = y * z
else if (z <= (-5.2d+26)) then
tmp = t_0
else if (z <= (-9.5d-22)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
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.1e+171) {
tmp = y * z;
} else if (z <= -5.2e+26) {
tmp = t_0;
} else if (z <= -9.5e-22) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3.1e+171: tmp = y * z elif z <= -5.2e+26: tmp = t_0 elif z <= -9.5e-22: tmp = y * z elif z <= 1.0: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -3.1e+171) tmp = Float64(y * z); elseif (z <= -5.2e+26) tmp = t_0; elseif (z <= -9.5e-22) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; 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.1e+171) tmp = y * z; elseif (z <= -5.2e+26) tmp = t_0; elseif (z <= -9.5e-22) tmp = y * z; elseif (z <= 1.0) tmp = x; 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.1e+171], N[(y * z), $MachinePrecision], If[LessEqual[z, -5.2e+26], t$95$0, If[LessEqual[z, -9.5e-22], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -3.1 \cdot 10^{+171}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -5.2 \cdot 10^{+26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{-22}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.0999999999999999e171 or -5.20000000000000004e26 < z < -9.4999999999999994e-22Initial program 100.0%
Taylor expanded in x around 0 97.5%
fma-def100.0%
mul-1-neg100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 64.7%
if -3.0999999999999999e171 < z < -5.20000000000000004e26 or 1 < z Initial program 100.0%
Taylor expanded in x around inf 65.3%
mul-1-neg65.3%
unsub-neg65.3%
Simplified65.3%
Taylor expanded in z around inf 63.9%
associate-*r*63.9%
mul-1-neg63.9%
Simplified63.9%
if -9.4999999999999994e-22 < z < 1Initial program 100.0%
Taylor expanded in z around 0 74.7%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.45e-133) (not (<= x 9.2e-55))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.45e-133) || !(x <= 9.2e-55)) {
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.45d-133)) .or. (.not. (x <= 9.2d-55))) 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.45e-133) || !(x <= 9.2e-55)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.45e-133) or not (x <= 9.2e-55): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.45e-133) || !(x <= 9.2e-55)) 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.45e-133) || ~((x <= 9.2e-55))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.45e-133], N[Not[LessEqual[x, 9.2e-55]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{-133} \lor \neg \left(x \leq 9.2 \cdot 10^{-55}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.44999999999999998e-133 or 9.20000000000000046e-55 < x Initial program 100.0%
Taylor expanded in x around inf 85.9%
mul-1-neg85.9%
unsub-neg85.9%
Simplified85.9%
if -2.44999999999999998e-133 < x < 9.20000000000000046e-55Initial program 100.0%
Taylor expanded in x around 0 100.0%
fma-def100.0%
mul-1-neg100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 73.1%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.8e-20) (not (<= z 3.2e-32))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.8e-20) || !(z <= 3.2e-32)) {
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 <= (-1.8d-20)) .or. (.not. (z <= 3.2d-32))) 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 <= -1.8e-20) || !(z <= 3.2e-32)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.8e-20) or not (z <= 3.2e-32): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.8e-20) || !(z <= 3.2e-32)) 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 <= -1.8e-20) || ~((z <= 3.2e-32))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.8e-20], N[Not[LessEqual[z, 3.2e-32]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{-20} \lor \neg \left(z \leq 3.2 \cdot 10^{-32}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.79999999999999987e-20 or 3.2000000000000002e-32 < z Initial program 100.0%
Taylor expanded in x around 0 97.9%
fma-def99.3%
mul-1-neg99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in z around inf 97.1%
mul-1-neg97.1%
unsub-neg97.1%
Simplified97.1%
if -1.79999999999999987e-20 < z < 3.2000000000000002e-32Initial program 100.0%
Taylor expanded in z around 0 77.5%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1160000000.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1160000000.0) || !(z <= 1.0)) {
tmp = (y - 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 ((z <= (-1160000000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = (y - 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 ((z <= -1160000000.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1160000000.0) or not (z <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1160000000.0) || !(z <= 1.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1160000000.0) || ~((z <= 1.0))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1160000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1160000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1.16e9 or 1 < z Initial program 100.0%
Taylor expanded in x around 0 97.7%
fma-def99.2%
mul-1-neg99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in z around inf 99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
if -1.16e9 < z < 1Initial program 100.0%
Taylor expanded in y around inf 98.7%
*-commutative98.7%
Simplified98.7%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.75e-18) (not (<= z 2.7e-32))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.75e-18) || !(z <= 2.7e-32)) {
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.75d-18)) .or. (.not. (z <= 2.7d-32))) 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.75e-18) || !(z <= 2.7e-32)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.75e-18) or not (z <= 2.7e-32): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.75e-18) || !(z <= 2.7e-32)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.75e-18) || ~((z <= 2.7e-32))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.75e-18], N[Not[LessEqual[z, 2.7e-32]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.75 \cdot 10^{-18} \lor \neg \left(z \leq 2.7 \cdot 10^{-32}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.75e-18 or 2.69999999999999981e-32 < z Initial program 100.0%
Taylor expanded in x around 0 97.9%
fma-def99.3%
mul-1-neg99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in x around 0 46.8%
if -2.75e-18 < z < 2.69999999999999981e-32Initial program 100.0%
Taylor expanded in z around 0 77.5%
Final simplification60.2%
(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 36.0%
Final simplification36.0%
herbie shell --seed 2024027
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))