
(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 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -4.2e+97)
(* y z)
(if (<= z -1.0)
t_0
(if (<= z 13000.0) x (if (<= z 2.8e+65) t_0 (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -4.2e+97) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 13000.0) {
tmp = x;
} else if (z <= 2.8e+65) {
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 = x * -z
if (z <= (-4.2d+97)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 13000.0d0) then
tmp = x
else if (z <= 2.8d+65) 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 = x * -z;
double tmp;
if (z <= -4.2e+97) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 13000.0) {
tmp = x;
} else if (z <= 2.8e+65) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -4.2e+97: tmp = y * z elif z <= -1.0: tmp = t_0 elif z <= 13000.0: tmp = x elif z <= 2.8e+65: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -4.2e+97) tmp = Float64(y * z); elseif (z <= -1.0) tmp = t_0; elseif (z <= 13000.0) tmp = x; elseif (z <= 2.8e+65) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -4.2e+97) tmp = y * z; elseif (z <= -1.0) tmp = t_0; elseif (z <= 13000.0) tmp = x; elseif (z <= 2.8e+65) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -4.2e+97], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 13000.0], x, If[LessEqual[z, 2.8e+65], t$95$0, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{+97}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 13000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.20000000000000023e97 or 2.7999999999999999e65 < z Initial program 100.0%
Taylor expanded in x around 0 62.6%
if -4.20000000000000023e97 < z < -1 or 13000 < z < 2.7999999999999999e65Initial program 99.9%
Taylor expanded in x around inf 79.4%
mul-1-neg79.4%
unsub-neg79.4%
Simplified79.4%
Taylor expanded in z around inf 77.1%
neg-mul-177.1%
Simplified77.1%
if -1 < z < 13000Initial program 100.0%
Taylor expanded in z around 0 72.3%
(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 100.0%
Taylor expanded in z around inf 99.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 98.6%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e-46) (not (<= z 7.5e-71))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-46) || !(z <= 7.5e-71)) {
tmp = (y - x) * 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.1d-46)) .or. (.not. (z <= 7.5d-71))) then
tmp = (y - x) * 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.1e-46) || !(z <= 7.5e-71)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e-46) or not (z <= 7.5e-71): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e-46) || !(z <= 7.5e-71)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e-46) || ~((z <= 7.5e-71))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e-46], N[Not[LessEqual[z, 7.5e-71]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-46} \lor \neg \left(z \leq 7.5 \cdot 10^{-71}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.1000000000000001e-46 or 7.5000000000000004e-71 < z Initial program 100.0%
Taylor expanded in z around inf 94.2%
if -3.1000000000000001e-46 < z < 7.5000000000000004e-71Initial program 100.0%
Taylor expanded in z around 0 78.8%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e-114) (not (<= x 2.55e-82))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e-114) || !(x <= 2.55e-82)) {
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.7d-114)) .or. (.not. (x <= 2.55d-82))) 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.7e-114) || !(x <= 2.55e-82)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e-114) or not (x <= 2.55e-82): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7e-114) || !(x <= 2.55e-82)) 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.7e-114) || ~((x <= 2.55e-82))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7e-114], N[Not[LessEqual[x, 2.55e-82]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{-114} \lor \neg \left(x \leq 2.55 \cdot 10^{-82}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.69999999999999965e-114 or 2.54999999999999996e-82 < x Initial program 100.0%
Taylor expanded in x around inf 81.4%
mul-1-neg81.4%
unsub-neg81.4%
Simplified81.4%
if -3.69999999999999965e-114 < x < 2.54999999999999996e-82Initial program 100.0%
Taylor expanded in x around 0 76.9%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.2e-44) (not (<= z 1.2e-69))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.2e-44) || !(z <= 1.2e-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 <= (-7.2d-44)) .or. (.not. (z <= 1.2d-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 <= -7.2e-44) || !(z <= 1.2e-69)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.2e-44) or not (z <= 1.2e-69): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.2e-44) || !(z <= 1.2e-69)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.2e-44) || ~((z <= 1.2e-69))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.2e-44], N[Not[LessEqual[z, 1.2e-69]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-44} \lor \neg \left(z \leq 1.2 \cdot 10^{-69}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.1999999999999998e-44 or 1.2000000000000001e-69 < z Initial program 100.0%
Taylor expanded in x around 0 53.5%
if -7.1999999999999998e-44 < z < 1.2000000000000001e-69Initial program 100.0%
Taylor expanded in z around 0 78.8%
Final simplification64.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%
(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 38.4%
herbie shell --seed 2024114
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))