
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -1.65e+250)
(* y z)
(if (<= z -1e+121)
t_0
(if (<= z -3.2e-46) (* y z) (if (<= z 1.0) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.65e+250) {
tmp = y * z;
} else if (z <= -1e+121) {
tmp = t_0;
} else if (z <= -3.2e-46) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
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 <= (-1.65d+250)) then
tmp = y * z
else if (z <= (-1d+121)) then
tmp = t_0
else if (z <= (-3.2d-46)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else
tmp = t_0
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 <= -1.65e+250) {
tmp = y * z;
} else if (z <= -1e+121) {
tmp = t_0;
} else if (z <= -3.2e-46) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.65e+250: tmp = y * z elif z <= -1e+121: tmp = t_0 elif z <= -3.2e-46: tmp = y * z elif z <= 1.0: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -1.65e+250) tmp = Float64(y * z); elseif (z <= -1e+121) tmp = t_0; elseif (z <= -3.2e-46) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -1.65e+250) tmp = y * z; elseif (z <= -1e+121) tmp = t_0; elseif (z <= -3.2e-46) tmp = y * z; elseif (z <= 1.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.65e+250], N[(y * z), $MachinePrecision], If[LessEqual[z, -1e+121], t$95$0, If[LessEqual[z, -3.2e-46], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.65 \cdot 10^{+250}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1 \cdot 10^{+121}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-46}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.65000000000000003e250 or -1.00000000000000004e121 < z < -3.1999999999999999e-46Initial program 100.0%
Taylor expanded in x around 0 69.5%
if -1.65000000000000003e250 < z < -1.00000000000000004e121 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 98.0%
Taylor expanded in y around 0 63.3%
mul-1-neg63.3%
distribute-lft-neg-out63.3%
*-commutative63.3%
Simplified63.3%
if -3.1999999999999999e-46 < z < 1Initial program 100.0%
Taylor expanded in z around 0 79.2%
Final simplification71.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.45e+122) (not (<= y 3e+93))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+122) || !(y <= 3e+93)) {
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 <= (-1.45d+122)) .or. (.not. (y <= 3d+93))) 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 <= -1.45e+122) || !(y <= 3e+93)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e+122) or not (y <= 3e+93): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e+122) || !(y <= 3e+93)) 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 <= -1.45e+122) || ~((y <= 3e+93))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+122], N[Not[LessEqual[y, 3e+93]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+122} \lor \neg \left(y \leq 3 \cdot 10^{+93}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -1.45e122 or 2.99999999999999978e93 < y Initial program 100.0%
Taylor expanded in x around 0 82.9%
if -1.45e122 < y < 2.99999999999999978e93Initial program 100.0%
Taylor expanded in x around inf 83.3%
mul-1-neg83.3%
unsub-neg83.3%
Simplified83.3%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e-48) (not (<= z 450000.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-48) || !(z <= 450000.0)) {
tmp = (y - x) * 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 ((z <= (-1.25d-48)) .or. (.not. (z <= 450000.0d0))) then
tmp = (y - x) * 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 ((z <= -1.25e-48) || !(z <= 450000.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.25e-48) or not (z <= 450000.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e-48) || !(z <= 450000.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.25e-48) || ~((z <= 450000.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e-48], N[Not[LessEqual[z, 450000.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-48} \lor \neg \left(z \leq 450000\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -1.25e-48 or 4.5e5 < z Initial program 100.0%
Taylor expanded in z around inf 98.6%
if -1.25e-48 < z < 4.5e5Initial program 99.9%
Taylor expanded in x around inf 80.6%
mul-1-neg80.6%
unsub-neg80.6%
Simplified80.6%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e-46) (not (<= z 1.18e-20))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-46) || !(z <= 1.18e-20)) {
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.15d-46)) .or. (.not. (z <= 1.18d-20))) 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.15e-46) || !(z <= 1.18e-20)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e-46) or not (z <= 1.18e-20): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e-46) || !(z <= 1.18e-20)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e-46) || ~((z <= 1.18e-20))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e-46], N[Not[LessEqual[z, 1.18e-20]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-46} \lor \neg \left(z \leq 1.18 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.15e-46 or 1.1800000000000001e-20 < z Initial program 99.9%
Taylor expanded in x around 0 50.2%
if -1.15e-46 < z < 1.1800000000000001e-20Initial program 100.0%
Taylor expanded in z around 0 80.6%
Final simplification62.3%
(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 34.4%
Final simplification34.4%
herbie shell --seed 2024083
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))