
(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-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e-7) (not (<= x 1.5e-34))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e-7) || !(x <= 1.5e-34)) {
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.9d-7)) .or. (.not. (x <= 1.5d-34))) 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.9e-7) || !(x <= 1.5e-34)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e-7) or not (x <= 1.5e-34): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e-7) || !(x <= 1.5e-34)) 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.9e-7) || ~((x <= 1.5e-34))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e-7], N[Not[LessEqual[x, 1.5e-34]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-7} \lor \neg \left(x \leq 1.5 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.90000000000000007e-7 or 1.5e-34 < x Initial program 99.9%
Taylor expanded in x around inf 85.2%
mul-1-neg85.2%
unsub-neg85.2%
Simplified85.2%
if -1.90000000000000007e-7 < x < 1.5e-34Initial program 100.0%
Taylor expanded in y around inf 90.0%
*-commutative90.0%
Simplified90.0%
Taylor expanded in y around inf 90.0%
Taylor expanded in y around inf 67.6%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e+78) (not (<= x 78000.0))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e+78) || !(x <= 78000.0)) {
tmp = x * (1.0 - 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 ((x <= (-1.25d+78)) .or. (.not. (x <= 78000.0d0))) then
tmp = x * (1.0d0 - 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 ((x <= -1.25e+78) || !(x <= 78000.0)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e+78) or not (x <= 78000.0): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e+78) || !(x <= 78000.0)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.25e+78) || ~((x <= 78000.0))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e+78], N[Not[LessEqual[x, 78000.0]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+78} \lor \neg \left(x \leq 78000\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.24999999999999996e78 or 78000 < x Initial program 100.0%
Taylor expanded in x around inf 92.7%
mul-1-neg92.7%
unsub-neg92.7%
Simplified92.7%
if -1.24999999999999996e78 < x < 78000Initial program 100.0%
Taylor expanded in y around inf 88.5%
*-commutative88.5%
Simplified88.5%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.85e-64) (not (<= z 7e-69))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.85e-64) || !(z <= 7e-69)) {
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 <= (-1.85d-64)) .or. (.not. (z <= 7d-69))) 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 <= -1.85e-64) || !(z <= 7e-69)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.85e-64) or not (z <= 7e-69): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.85e-64) || !(z <= 7e-69)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.85e-64) || ~((z <= 7e-69))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.85e-64], N[Not[LessEqual[z, 7e-69]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{-64} \lor \neg \left(z \leq 7 \cdot 10^{-69}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.84999999999999999e-64 or 7.0000000000000003e-69 < z Initial program 99.9%
Taylor expanded in y around inf 61.7%
*-commutative61.7%
Simplified61.7%
Taylor expanded in y around inf 62.8%
Taylor expanded in y around inf 56.3%
if -1.84999999999999999e-64 < z < 7.0000000000000003e-69Initial program 100.0%
Taylor expanded in z around 0 84.1%
Final simplification66.6%
(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.1%
Final simplification36.1%
herbie shell --seed 2024050
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))