
(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 -7.2e-59) (* y z) (if (<= z 7.6e-131) x (if (<= z 1.3e+74) (* y z) (* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e-59) {
tmp = y * z;
} else if (z <= 7.6e-131) {
tmp = x;
} else if (z <= 1.3e+74) {
tmp = y * z;
} else {
tmp = x * -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.2d-59)) then
tmp = y * z
else if (z <= 7.6d-131) then
tmp = x
else if (z <= 1.3d+74) then
tmp = y * z
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e-59) {
tmp = y * z;
} else if (z <= 7.6e-131) {
tmp = x;
} else if (z <= 1.3e+74) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.2e-59: tmp = y * z elif z <= 7.6e-131: tmp = x elif z <= 1.3e+74: tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.2e-59) tmp = Float64(y * z); elseif (z <= 7.6e-131) tmp = x; elseif (z <= 1.3e+74) tmp = Float64(y * z); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.2e-59) tmp = y * z; elseif (z <= 7.6e-131) tmp = x; elseif (z <= 1.3e+74) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.2e-59], N[(y * z), $MachinePrecision], If[LessEqual[z, 7.6e-131], x, If[LessEqual[z, 1.3e+74], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-59}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7.6 \cdot 10^{-131}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+74}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -7.20000000000000001e-59 or 7.59999999999999989e-131 < z < 1.3e74Initial program 100.0%
Taylor expanded in y around inf 73.6%
*-commutative73.6%
Simplified73.6%
Taylor expanded in z around inf 73.6%
Taylor expanded in y around inf 62.4%
if -7.20000000000000001e-59 < z < 7.59999999999999989e-131Initial program 100.0%
Taylor expanded in z around 0 76.3%
if 1.3e74 < z Initial program 100.0%
Taylor expanded in x around inf 68.5%
mul-1-neg68.5%
unsub-neg68.5%
Simplified68.5%
Taylor expanded in z around inf 68.5%
neg-mul-168.5%
Simplified68.5%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -420000.0) (not (<= y 140000000000.0))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -420000.0) || !(y <= 140000000000.0)) {
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 <= (-420000.0d0)) .or. (.not. (y <= 140000000000.0d0))) 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 <= -420000.0) || !(y <= 140000000000.0)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -420000.0) or not (y <= 140000000000.0): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -420000.0) || !(y <= 140000000000.0)) 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 <= -420000.0) || ~((y <= 140000000000.0))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -420000.0], N[Not[LessEqual[y, 140000000000.0]], $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 -420000 \lor \neg \left(y \leq 140000000000\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -4.2e5 or 1.4e11 < y Initial program 100.0%
Taylor expanded in y around inf 95.1%
*-commutative95.1%
Simplified95.1%
if -4.2e5 < y < 1.4e11Initial program 100.0%
Taylor expanded in x around inf 84.3%
mul-1-neg84.3%
unsub-neg84.3%
Simplified84.3%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.12e-12) (not (<= x 3.5e-30))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e-12) || !(x <= 3.5e-30)) {
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.12d-12)) .or. (.not. (x <= 3.5d-30))) 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.12e-12) || !(x <= 3.5e-30)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.12e-12) or not (x <= 3.5e-30): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.12e-12) || !(x <= 3.5e-30)) 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.12e-12) || ~((x <= 3.5e-30))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.12e-12], N[Not[LessEqual[x, 3.5e-30]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-12} \lor \neg \left(x \leq 3.5 \cdot 10^{-30}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.1200000000000001e-12 or 3.5000000000000003e-30 < x Initial program 100.0%
Taylor expanded in x around inf 84.7%
mul-1-neg84.7%
unsub-neg84.7%
Simplified84.7%
if -1.1200000000000001e-12 < x < 3.5000000000000003e-30Initial program 100.0%
Taylor expanded in y around inf 87.6%
*-commutative87.6%
Simplified87.6%
Taylor expanded in z around inf 87.6%
Taylor expanded in y around inf 69.3%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.95e-58) (not (<= z 5.6e-131))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.95e-58) || !(z <= 5.6e-131)) {
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.95d-58)) .or. (.not. (z <= 5.6d-131))) 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.95e-58) || !(z <= 5.6e-131)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.95e-58) or not (z <= 5.6e-131): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.95e-58) || !(z <= 5.6e-131)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.95e-58) || ~((z <= 5.6e-131))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.95e-58], N[Not[LessEqual[z, 5.6e-131]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{-58} \lor \neg \left(z \leq 5.6 \cdot 10^{-131}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.94999999999999996e-58 or 5.5999999999999999e-131 < z Initial program 100.0%
Taylor expanded in y around inf 63.4%
*-commutative63.4%
Simplified63.4%
Taylor expanded in z around inf 63.4%
Taylor expanded in y around inf 55.7%
if -1.94999999999999996e-58 < z < 5.5999999999999999e-131Initial program 100.0%
Taylor expanded in z around 0 76.3%
Final simplification63.5%
(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 35.4%
herbie shell --seed 2024159
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))