
(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 6 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
(if (<= z -4.2e-109)
(* y z)
(if (<= z 6.5e-222)
x
(if (<= z 1.22e-200) (* y z) (if (<= z 2.2e-75) x (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e-109) {
tmp = y * z;
} else if (z <= 6.5e-222) {
tmp = x;
} else if (z <= 1.22e-200) {
tmp = y * z;
} else if (z <= 2.2e-75) {
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 <= (-4.2d-109)) then
tmp = y * z
else if (z <= 6.5d-222) then
tmp = x
else if (z <= 1.22d-200) then
tmp = y * z
else if (z <= 2.2d-75) 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 <= -4.2e-109) {
tmp = y * z;
} else if (z <= 6.5e-222) {
tmp = x;
} else if (z <= 1.22e-200) {
tmp = y * z;
} else if (z <= 2.2e-75) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e-109: tmp = y * z elif z <= 6.5e-222: tmp = x elif z <= 1.22e-200: tmp = y * z elif z <= 2.2e-75: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e-109) tmp = Float64(y * z); elseif (z <= 6.5e-222) tmp = x; elseif (z <= 1.22e-200) tmp = Float64(y * z); elseif (z <= 2.2e-75) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.2e-109) tmp = y * z; elseif (z <= 6.5e-222) tmp = x; elseif (z <= 1.22e-200) tmp = y * z; elseif (z <= 2.2e-75) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e-109], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.5e-222], x, If[LessEqual[z, 1.22e-200], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.2e-75], x, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{-109}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-222}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.22 \cdot 10^{-200}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-75}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.19999999999999992e-109 or 6.5000000000000005e-222 < z < 1.22000000000000005e-200 or 2.20000000000000005e-75 < z Initial program 100.0%
Taylor expanded in y around inf 67.6%
*-commutative67.6%
Simplified67.6%
Taylor expanded in x around 0 59.1%
*-commutative59.1%
Simplified59.1%
if -4.19999999999999992e-109 < z < 6.5000000000000005e-222 or 1.22000000000000005e-200 < z < 2.20000000000000005e-75Initial program 100.0%
Taylor expanded in z around 0 84.6%
Final simplification66.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e-70) (not (<= x 8.5e-140))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-70) || !(x <= 8.5e-140)) {
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.8d-70)) .or. (.not. (x <= 8.5d-140))) 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.8e-70) || !(x <= 8.5e-140)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e-70) or not (x <= 8.5e-140): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e-70) || !(x <= 8.5e-140)) 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.8e-70) || ~((x <= 8.5e-140))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e-70], N[Not[LessEqual[x, 8.5e-140]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-70} \lor \neg \left(x \leq 8.5 \cdot 10^{-140}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.7999999999999999e-70 or 8.49999999999999997e-140 < x Initial program 100.0%
Taylor expanded in x around inf 75.3%
mul-1-neg75.3%
Simplified75.3%
Taylor expanded in x around 0 75.3%
if -2.7999999999999999e-70 < x < 8.49999999999999997e-140Initial program 100.0%
Taylor expanded in y around inf 93.6%
*-commutative93.6%
Simplified93.6%
Taylor expanded in x around 0 80.3%
*-commutative80.3%
Simplified80.3%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.4e-46) (not (<= y 3.6e-75))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.4e-46) || !(y <= 3.6e-75)) {
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 <= (-7.4d-46)) .or. (.not. (y <= 3.6d-75))) 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 <= -7.4e-46) || !(y <= 3.6e-75)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.4e-46) or not (y <= 3.6e-75): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.4e-46) || !(y <= 3.6e-75)) 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 <= -7.4e-46) || ~((y <= 3.6e-75))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.4e-46], N[Not[LessEqual[y, 3.6e-75]], $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 -7.4 \cdot 10^{-46} \lor \neg \left(y \leq 3.6 \cdot 10^{-75}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -7.39999999999999966e-46 or 3.6e-75 < y Initial program 100.0%
Taylor expanded in y around inf 89.7%
*-commutative89.7%
Simplified89.7%
if -7.39999999999999966e-46 < y < 3.6e-75Initial program 100.0%
Taylor expanded in x around inf 88.8%
mul-1-neg88.8%
Simplified88.8%
Taylor expanded in x around 0 88.8%
Final simplification89.4%
(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.8%
Final simplification32.8%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))