
(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-define100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= z -38000000.0) (* x (- z)) (if (or (<= z -2.55e-26) (not (<= z 2e-31))) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -38000000.0) {
tmp = x * -z;
} else if ((z <= -2.55e-26) || !(z <= 2e-31)) {
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 <= (-38000000.0d0)) then
tmp = x * -z
else if ((z <= (-2.55d-26)) .or. (.not. (z <= 2d-31))) 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 <= -38000000.0) {
tmp = x * -z;
} else if ((z <= -2.55e-26) || !(z <= 2e-31)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -38000000.0: tmp = x * -z elif (z <= -2.55e-26) or not (z <= 2e-31): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -38000000.0) tmp = Float64(x * Float64(-z)); elseif ((z <= -2.55e-26) || !(z <= 2e-31)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -38000000.0) tmp = x * -z; elseif ((z <= -2.55e-26) || ~((z <= 2e-31))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -38000000.0], N[(x * (-z)), $MachinePrecision], If[Or[LessEqual[z, -2.55e-26], N[Not[LessEqual[z, 2e-31]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -38000000:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;z \leq -2.55 \cdot 10^{-26} \lor \neg \left(z \leq 2 \cdot 10^{-31}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.8e7Initial program 100.0%
Taylor expanded in x around inf 61.0%
mul-1-neg61.0%
unsub-neg61.0%
Simplified61.0%
Taylor expanded in z around inf 60.4%
neg-mul-160.4%
distribute-rgt-neg-in60.4%
Simplified60.4%
if -3.8e7 < z < -2.54999999999999995e-26 or 2e-31 < z Initial program 100.0%
Taylor expanded in y around inf 64.1%
*-commutative64.1%
Simplified64.1%
Taylor expanded in x around 0 59.9%
*-commutative59.9%
Simplified59.9%
if -2.54999999999999995e-26 < z < 2e-31Initial program 100.0%
Taylor expanded in z around 0 79.0%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e+88) (not (<= x 1.95e-6))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e+88) || !(x <= 1.95e-6)) {
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 <= (-3.3d+88)) .or. (.not. (x <= 1.95d-6))) 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 <= -3.3e+88) || !(x <= 1.95e-6)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e+88) or not (x <= 1.95e-6): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e+88) || !(x <= 1.95e-6)) 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 <= -3.3e+88) || ~((x <= 1.95e-6))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e+88], N[Not[LessEqual[x, 1.95e-6]], $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 -3.3 \cdot 10^{+88} \lor \neg \left(x \leq 1.95 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -3.3000000000000003e88 or 1.95e-6 < x Initial program 100.0%
Taylor expanded in x around inf 90.2%
mul-1-neg90.2%
unsub-neg90.2%
Simplified90.2%
if -3.3000000000000003e88 < x < 1.95e-6Initial program 100.0%
Taylor expanded in y around inf 87.0%
*-commutative87.0%
Simplified87.0%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.5e+162) (not (<= y 1.3e+110))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e+162) || !(y <= 1.3e+110)) {
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 <= (-8.5d+162)) .or. (.not. (y <= 1.3d+110))) 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 <= -8.5e+162) || !(y <= 1.3e+110)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.5e+162) or not (y <= 1.3e+110): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.5e+162) || !(y <= 1.3e+110)) 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 <= -8.5e+162) || ~((y <= 1.3e+110))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.5e+162], N[Not[LessEqual[y, 1.3e+110]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+162} \lor \neg \left(y \leq 1.3 \cdot 10^{+110}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -8.5000000000000003e162 or 1.3e110 < y Initial program 100.0%
Taylor expanded in y around inf 95.8%
*-commutative95.8%
Simplified95.8%
Taylor expanded in x around 0 74.7%
*-commutative74.7%
Simplified74.7%
if -8.5000000000000003e162 < y < 1.3e110Initial program 100.0%
Taylor expanded in x around inf 76.8%
mul-1-neg76.8%
unsub-neg76.8%
Simplified76.8%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-27) (not (<= z 3.5e-31))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-27) || !(z <= 3.5e-31)) {
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 <= (-3.5d-27)) .or. (.not. (z <= 3.5d-31))) 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 <= -3.5e-27) || !(z <= 3.5e-31)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e-27) or not (z <= 3.5e-31): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-27) || !(z <= 3.5e-31)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.5e-27) || ~((z <= 3.5e-31))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e-27], N[Not[LessEqual[z, 3.5e-31]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-27} \lor \neg \left(z \leq 3.5 \cdot 10^{-31}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.5000000000000001e-27 or 3.49999999999999985e-31 < z Initial program 100.0%
Taylor expanded in y around inf 53.1%
*-commutative53.1%
Simplified53.1%
Taylor expanded in x around 0 50.2%
*-commutative50.2%
Simplified50.2%
if -3.5000000000000001e-27 < z < 3.49999999999999985e-31Initial program 100.0%
Taylor expanded in z around 0 79.0%
Final simplification63.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%
(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 39.0%
herbie shell --seed 2024128
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))