
(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 5 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 (+ 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
(if (or (<= y -2.5e-55)
(and (not (<= y -4.4e-97))
(or (<= y -9.2e-132) (not (<= y 3.6e+42)))))
(+ x (* y z))
(* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-55) || (!(y <= -4.4e-97) && ((y <= -9.2e-132) || !(y <= 3.6e+42)))) {
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 <= (-2.5d-55)) .or. (.not. (y <= (-4.4d-97))) .and. (y <= (-9.2d-132)) .or. (.not. (y <= 3.6d+42))) 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 <= -2.5e-55) || (!(y <= -4.4e-97) && ((y <= -9.2e-132) || !(y <= 3.6e+42)))) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-55) or (not (y <= -4.4e-97) and ((y <= -9.2e-132) or not (y <= 3.6e+42))): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-55) || (!(y <= -4.4e-97) && ((y <= -9.2e-132) || !(y <= 3.6e+42)))) 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 <= -2.5e-55) || (~((y <= -4.4e-97)) && ((y <= -9.2e-132) || ~((y <= 3.6e+42))))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-55], And[N[Not[LessEqual[y, -4.4e-97]], $MachinePrecision], Or[LessEqual[y, -9.2e-132], N[Not[LessEqual[y, 3.6e+42]], $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 -2.5 \cdot 10^{-55} \lor \neg \left(y \leq -4.4 \cdot 10^{-97}\right) \land \left(y \leq -9.2 \cdot 10^{-132} \lor \neg \left(y \leq 3.6 \cdot 10^{+42}\right)\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.5000000000000001e-55 or -4.3999999999999998e-97 < y < -9.20000000000000012e-132 or 3.6000000000000001e42 < y Initial program 100.0%
Taylor expanded in y around inf 91.4%
*-commutative91.4%
Simplified91.4%
if -2.5000000000000001e-55 < y < -4.3999999999999998e-97 or -9.20000000000000012e-132 < y < 3.6000000000000001e42Initial program 100.0%
Taylor expanded in x around inf 90.0%
mul-1-neg90.0%
unsub-neg90.0%
Simplified90.0%
Final simplification90.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* y z))))
(if (<= y -1.65e-55)
t_0
(if (<= y -4e-97)
(* x (- 1.0 z))
(if (or (<= y -9.2e-132) (not (<= y 4e+42))) t_0 (- x (* x z)))))))
double code(double x, double y, double z) {
double t_0 = x + (y * z);
double tmp;
if (y <= -1.65e-55) {
tmp = t_0;
} else if (y <= -4e-97) {
tmp = x * (1.0 - z);
} else if ((y <= -9.2e-132) || !(y <= 4e+42)) {
tmp = t_0;
} else {
tmp = x - (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) :: t_0
real(8) :: tmp
t_0 = x + (y * z)
if (y <= (-1.65d-55)) then
tmp = t_0
else if (y <= (-4d-97)) then
tmp = x * (1.0d0 - z)
else if ((y <= (-9.2d-132)) .or. (.not. (y <= 4d+42))) then
tmp = t_0
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y * z);
double tmp;
if (y <= -1.65e-55) {
tmp = t_0;
} else if (y <= -4e-97) {
tmp = x * (1.0 - z);
} else if ((y <= -9.2e-132) || !(y <= 4e+42)) {
tmp = t_0;
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): t_0 = x + (y * z) tmp = 0 if y <= -1.65e-55: tmp = t_0 elif y <= -4e-97: tmp = x * (1.0 - z) elif (y <= -9.2e-132) or not (y <= 4e+42): tmp = t_0 else: tmp = x - (x * z) return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y * z)) tmp = 0.0 if (y <= -1.65e-55) tmp = t_0; elseif (y <= -4e-97) tmp = Float64(x * Float64(1.0 - z)); elseif ((y <= -9.2e-132) || !(y <= 4e+42)) tmp = t_0; else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y * z); tmp = 0.0; if (y <= -1.65e-55) tmp = t_0; elseif (y <= -4e-97) tmp = x * (1.0 - z); elseif ((y <= -9.2e-132) || ~((y <= 4e+42))) tmp = t_0; else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.65e-55], t$95$0, If[LessEqual[y, -4e-97], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -9.2e-132], N[Not[LessEqual[y, 4e+42]], $MachinePrecision]], t$95$0, N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + y \cdot z\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{-55}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -4 \cdot 10^{-97}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-132} \lor \neg \left(y \leq 4 \cdot 10^{+42}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if y < -1.65e-55 or -4.00000000000000014e-97 < y < -9.20000000000000012e-132 or 4.00000000000000018e42 < y Initial program 100.0%
Taylor expanded in y around inf 91.4%
*-commutative91.4%
Simplified91.4%
if -1.65e-55 < y < -4.00000000000000014e-97Initial program 100.0%
Taylor expanded in x around inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -9.20000000000000012e-132 < y < 4.00000000000000018e42Initial program 100.0%
Taylor expanded in x around inf 90.0%
mul-1-neg90.0%
unsub-neg90.0%
Simplified90.0%
sub-neg90.0%
distribute-rgt-in90.0%
*-un-lft-identity90.0%
distribute-lft-neg-in90.0%
unsub-neg90.0%
Applied egg-rr90.0%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (* x (- 1.0 z)))
double code(double x, double y, double z) {
return x * (1.0 - 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 * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return x * (1.0 - z);
}
def code(x, y, z): return x * (1.0 - z)
function code(x, y, z) return Float64(x * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = x * (1.0 - z); end
code[x_, y_, z_] := N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - z\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 62.8%
mul-1-neg62.8%
unsub-neg62.8%
Simplified62.8%
(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 36.5%
herbie shell --seed 2024111
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))