
(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 (* (- y x) z)))
(if (<= z -0.98)
t_0
(if (<= z 6e-92)
(* x (- 1.0 z))
(if (<= z 1.45e-63) (* y z) (if (<= z 2.1e-40) x t_0))))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -0.98) {
tmp = t_0;
} else if (z <= 6e-92) {
tmp = x * (1.0 - z);
} else if (z <= 1.45e-63) {
tmp = y * z;
} else if (z <= 2.1e-40) {
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 = (y - x) * z
if (z <= (-0.98d0)) then
tmp = t_0
else if (z <= 6d-92) then
tmp = x * (1.0d0 - z)
else if (z <= 1.45d-63) then
tmp = y * z
else if (z <= 2.1d-40) 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 = (y - x) * z;
double tmp;
if (z <= -0.98) {
tmp = t_0;
} else if (z <= 6e-92) {
tmp = x * (1.0 - z);
} else if (z <= 1.45e-63) {
tmp = y * z;
} else if (z <= 2.1e-40) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -0.98: tmp = t_0 elif z <= 6e-92: tmp = x * (1.0 - z) elif z <= 1.45e-63: tmp = y * z elif z <= 2.1e-40: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -0.98) tmp = t_0; elseif (z <= 6e-92) tmp = Float64(x * Float64(1.0 - z)); elseif (z <= 1.45e-63) tmp = Float64(y * z); elseif (z <= 2.1e-40) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) * z; tmp = 0.0; if (z <= -0.98) tmp = t_0; elseif (z <= 6e-92) tmp = x * (1.0 - z); elseif (z <= 1.45e-63) tmp = y * z; elseif (z <= 2.1e-40) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -0.98], t$95$0, If[LessEqual[z, 6e-92], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.45e-63], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.1e-40], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -0.98:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-92}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-40}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -0.97999999999999998 or 2.10000000000000018e-40 < z Initial program 99.9%
Taylor expanded in z around inf 96.7%
if -0.97999999999999998 < z < 6.00000000000000027e-92Initial program 100.0%
Taylor expanded in x around inf 73.3%
mul-1-neg73.3%
unsub-neg73.3%
Simplified73.3%
if 6.00000000000000027e-92 < z < 1.44999999999999987e-63Initial program 100.0%
Taylor expanded in x around 0 100.0%
if 1.44999999999999987e-63 < z < 2.10000000000000018e-40Initial program 100.0%
Taylor expanded in z around 0 84.3%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.9e+29) (not (<= y 4e+80))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.9e+29) || !(y <= 4e+80)) {
tmp = 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 <= (-2.9d+29)) .or. (.not. (y <= 4d+80))) then
tmp = 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 <= -2.9e+29) || !(y <= 4e+80)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.9e+29) or not (y <= 4e+80): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.9e+29) || !(y <= 4e+80)) tmp = 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 <= -2.9e+29) || ~((y <= 4e+80))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.9e+29], N[Not[LessEqual[y, 4e+80]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+29} \lor \neg \left(y \leq 4 \cdot 10^{+80}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.8999999999999999e29 or 4e80 < y Initial program 100.0%
Taylor expanded in x around 0 83.0%
if -2.8999999999999999e29 < y < 4e80Initial program 100.0%
Taylor expanded in x around inf 79.7%
mul-1-neg79.7%
unsub-neg79.7%
Simplified79.7%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -57000.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -57000.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 <= (-57000.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 <= -57000.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -57000.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 <= -57000.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 <= -57000.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, -57000.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 -57000 \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 < -57000 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 99.2%
if -57000 < z < 1Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 97.6%
*-commutative97.6%
Simplified97.6%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.05e-23) (not (<= z 5.6e-92))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.05e-23) || !(z <= 5.6e-92)) {
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.05d-23)) .or. (.not. (z <= 5.6d-92))) 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.05e-23) || !(z <= 5.6e-92)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.05e-23) or not (z <= 5.6e-92): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.05e-23) || !(z <= 5.6e-92)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.05e-23) || ~((z <= 5.6e-92))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.05e-23], N[Not[LessEqual[z, 5.6e-92]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.05 \cdot 10^{-23} \lor \neg \left(z \leq 5.6 \cdot 10^{-92}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.05000000000000015e-23 or 5.6e-92 < z Initial program 100.0%
Taylor expanded in x around 0 56.7%
if -2.05000000000000015e-23 < z < 5.6e-92Initial program 100.0%
Taylor expanded in z around 0 73.9%
Final simplification63.1%
(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 32.3%
Final simplification32.3%
herbie shell --seed 2023320
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))