
(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 99.9%
+-commutative99.9%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -4.5e+133)
(* y z)
(if (<= z -1.0)
t_0
(if (<= z 1.35e-38)
x
(if (<= z 1.22e+57) (* y z) (if (<= z 5.7e+211) t_0 (* y z))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -4.5e+133) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.35e-38) {
tmp = x;
} else if (z <= 1.22e+57) {
tmp = y * z;
} else if (z <= 5.7e+211) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (z <= (-4.5d+133)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.35d-38) then
tmp = x
else if (z <= 1.22d+57) then
tmp = y * z
else if (z <= 5.7d+211) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -4.5e+133) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.35e-38) {
tmp = x;
} else if (z <= 1.22e+57) {
tmp = y * z;
} else if (z <= 5.7e+211) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -4.5e+133: tmp = y * z elif z <= -1.0: tmp = t_0 elif z <= 1.35e-38: tmp = x elif z <= 1.22e+57: tmp = y * z elif z <= 5.7e+211: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -4.5e+133) tmp = Float64(y * z); elseif (z <= -1.0) tmp = t_0; elseif (z <= 1.35e-38) tmp = x; elseif (z <= 1.22e+57) tmp = Float64(y * z); elseif (z <= 5.7e+211) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -4.5e+133) tmp = y * z; elseif (z <= -1.0) tmp = t_0; elseif (z <= 1.35e-38) tmp = x; elseif (z <= 1.22e+57) tmp = y * z; elseif (z <= 5.7e+211) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -4.5e+133], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 1.35e-38], x, If[LessEqual[z, 1.22e+57], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.7e+211], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -4.5 \cdot 10^{+133}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.22 \cdot 10^{+57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.7 \cdot 10^{+211}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.49999999999999985e133 or 1.35000000000000003e-38 < z < 1.22e57 or 5.70000000000000001e211 < z Initial program 100.0%
Taylor expanded in x around 0 66.9%
if -4.49999999999999985e133 < z < -1 or 1.22e57 < z < 5.70000000000000001e211Initial program 99.9%
Taylor expanded in z around inf 98.5%
Taylor expanded in y around 0 63.0%
mul-1-neg63.0%
distribute-rgt-neg-out63.0%
Simplified63.0%
if -1 < z < 1.35000000000000003e-38Initial program 100.0%
Taylor expanded in z around 0 72.0%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-33) (not (<= x 5.5e-45))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-33) || !(x <= 5.5e-45)) {
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 <= (-3.1d-33)) .or. (.not. (x <= 5.5d-45))) 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 <= -3.1e-33) || !(x <= 5.5e-45)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-33) or not (x <= 5.5e-45): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-33) || !(x <= 5.5e-45)) 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 <= -3.1e-33) || ~((x <= 5.5e-45))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-33], N[Not[LessEqual[x, 5.5e-45]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-33} \lor \neg \left(x \leq 5.5 \cdot 10^{-45}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.09999999999999997e-33 or 5.5000000000000003e-45 < x Initial program 100.0%
Taylor expanded in x around inf 84.4%
distribute-rgt1-in84.4%
mul-1-neg84.4%
cancel-sign-sub-inv84.4%
Simplified84.4%
Taylor expanded in x around 0 84.4%
if -3.09999999999999997e-33 < x < 5.5000000000000003e-45Initial program 99.9%
Taylor expanded in x around 0 69.8%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.95e+14) (not (<= z 520000.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.95e+14) || !(z <= 520000.0)) {
tmp = (y - x) * 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 ((z <= (-1.95d+14)) .or. (.not. (z <= 520000.0d0))) then
tmp = (y - x) * 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 ((z <= -1.95e+14) || !(z <= 520000.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.95e+14) or not (z <= 520000.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.95e+14) || !(z <= 520000.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.95e+14) || ~((z <= 520000.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.95e+14], N[Not[LessEqual[z, 520000.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+14} \lor \neg \left(z \leq 520000\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -1.95e14 or 5.2e5 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
if -1.95e14 < z < 5.2e5Initial program 99.9%
Taylor expanded in x around inf 71.8%
distribute-rgt1-in71.8%
mul-1-neg71.8%
cancel-sign-sub-inv71.8%
Simplified71.8%
Taylor expanded in x around 0 71.8%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.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 <= (-1.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 <= -1.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \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 or 1 < z Initial program 99.9%
Taylor expanded in z around inf 98.4%
if -1 < z < 1Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
distribute-lft-in99.9%
Applied egg-rr99.9%
Taylor expanded in y around inf 97.7%
*-commutative97.7%
Simplified97.7%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (<= z -7.6e-100) (* y z) (if (<= z 5.2e-38) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e-100) {
tmp = y * z;
} else if (z <= 5.2e-38) {
tmp = x;
} 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-100)) then
tmp = y * z
else if (z <= 5.2d-38) then
tmp = x
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-100) {
tmp = y * z;
} else if (z <= 5.2e-38) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.6e-100: tmp = y * z elif z <= 5.2e-38: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.6e-100) tmp = Float64(y * z); elseif (z <= 5.2e-38) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.6e-100) tmp = y * z; elseif (z <= 5.2e-38) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.6e-100], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.2e-38], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{-100}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -7.59999999999999995e-100 or 5.20000000000000022e-38 < z Initial program 99.9%
Taylor expanded in x around 0 54.4%
if -7.59999999999999995e-100 < z < 5.20000000000000022e-38Initial program 100.0%
Taylor expanded in z around 0 77.6%
Final simplification64.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 99.9%
Final simplification99.9%
(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 99.9%
Taylor expanded in z around 0 38.6%
Final simplification38.6%
herbie shell --seed 2023258
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))