
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -6.5e+129)
(* y z)
(if (<= z -1.65e+98)
t_0
(if (<= z -53000.0)
(* y z)
(if (<= z 6e-68) x (if (<= z 1.15e+56) (* y z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -6.5e+129) {
tmp = y * z;
} else if (z <= -1.65e+98) {
tmp = t_0;
} else if (z <= -53000.0) {
tmp = y * z;
} else if (z <= 6e-68) {
tmp = x;
} else if (z <= 1.15e+56) {
tmp = y * z;
} 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 <= (-6.5d+129)) then
tmp = y * z
else if (z <= (-1.65d+98)) then
tmp = t_0
else if (z <= (-53000.0d0)) then
tmp = y * z
else if (z <= 6d-68) then
tmp = x
else if (z <= 1.15d+56) then
tmp = y * z
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 <= -6.5e+129) {
tmp = y * z;
} else if (z <= -1.65e+98) {
tmp = t_0;
} else if (z <= -53000.0) {
tmp = y * z;
} else if (z <= 6e-68) {
tmp = x;
} else if (z <= 1.15e+56) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -6.5e+129: tmp = y * z elif z <= -1.65e+98: tmp = t_0 elif z <= -53000.0: tmp = y * z elif z <= 6e-68: tmp = x elif z <= 1.15e+56: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -6.5e+129) tmp = Float64(y * z); elseif (z <= -1.65e+98) tmp = t_0; elseif (z <= -53000.0) tmp = Float64(y * z); elseif (z <= 6e-68) tmp = x; elseif (z <= 1.15e+56) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -6.5e+129) tmp = y * z; elseif (z <= -1.65e+98) tmp = t_0; elseif (z <= -53000.0) tmp = y * z; elseif (z <= 6e-68) tmp = x; elseif (z <= 1.15e+56) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -6.5e+129], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.65e+98], t$95$0, If[LessEqual[z, -53000.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 6e-68], x, If[LessEqual[z, 1.15e+56], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -6.5 \cdot 10^{+129}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.65 \cdot 10^{+98}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -53000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-68}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+56}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -6.4999999999999995e129 or -1.65000000000000014e98 < z < -53000 or 6e-68 < z < 1.15000000000000007e56Initial program 99.9%
Taylor expanded in x around 0 59.8%
if -6.4999999999999995e129 < z < -1.65000000000000014e98 or 1.15000000000000007e56 < z Initial program 100.0%
Taylor expanded in x around inf 71.5%
mul-1-neg71.5%
unsub-neg71.5%
Simplified71.5%
Taylor expanded in z around inf 71.5%
mul-1-neg71.5%
distribute-rgt-neg-out71.5%
Simplified71.5%
if -53000 < z < 6e-68Initial program 100.0%
Taylor expanded in z around 0 77.2%
Final simplification70.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-100) (not (<= x 7.4e-116))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-100) || !(x <= 7.4e-116)) {
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 <= (-2d-100)) .or. (.not. (x <= 7.4d-116))) 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 <= -2e-100) || !(x <= 7.4e-116)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-100) or not (x <= 7.4e-116): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-100) || !(x <= 7.4e-116)) 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 <= -2e-100) || ~((x <= 7.4e-116))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-100], N[Not[LessEqual[x, 7.4e-116]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-100} \lor \neg \left(x \leq 7.4 \cdot 10^{-116}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2e-100 or 7.4000000000000005e-116 < x Initial program 100.0%
Taylor expanded in x around inf 83.6%
mul-1-neg83.6%
unsub-neg83.6%
Simplified83.6%
if -2e-100 < x < 7.4000000000000005e-116Initial program 100.0%
Taylor expanded in x around 0 77.3%
Final simplification81.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -50000.0) (not (<= z 6.4e-68))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -50000.0) || !(z <= 6.4e-68)) {
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 <= (-50000.0d0)) .or. (.not. (z <= 6.4d-68))) 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 <= -50000.0) || !(z <= 6.4e-68)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -50000.0) or not (z <= 6.4e-68): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -50000.0) || !(z <= 6.4e-68)) 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 <= -50000.0) || ~((z <= 6.4e-68))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -50000.0], N[Not[LessEqual[z, 6.4e-68]], $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 -50000 \lor \neg \left(z \leq 6.4 \cdot 10^{-68}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -5e4 or 6.3999999999999998e-68 < z Initial program 100.0%
Taylor expanded in z around inf 96.9%
if -5e4 < z < 6.3999999999999998e-68Initial program 100.0%
Taylor expanded in x around inf 79.1%
mul-1-neg79.1%
unsub-neg79.1%
Simplified79.1%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -47000.0) (not (<= z 4.9e-68))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -47000.0) || !(z <= 4.9e-68)) {
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 <= (-47000.0d0)) .or. (.not. (z <= 4.9d-68))) 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 <= -47000.0) || !(z <= 4.9e-68)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -47000.0) or not (z <= 4.9e-68): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -47000.0) || !(z <= 4.9e-68)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -47000.0) || ~((z <= 4.9e-68))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -47000.0], N[Not[LessEqual[z, 4.9e-68]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -47000 \lor \neg \left(z \leq 4.9 \cdot 10^{-68}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -47000 or 4.89999999999999977e-68 < z Initial program 100.0%
Taylor expanded in x around 0 51.9%
if -47000 < z < 4.89999999999999977e-68Initial program 100.0%
Taylor expanded in z around 0 77.2%
Final simplification64.1%
(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 39.6%
Final simplification39.6%
herbie shell --seed 2024021
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))