
(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 (+ 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 -3.4e+57) (not (<= y 2.4e-74))) (+ x (* y z)) (- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e+57) || !(y <= 2.4e-74)) {
tmp = x + (y * z);
} 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) :: tmp
if ((y <= (-3.4d+57)) .or. (.not. (y <= 2.4d-74))) then
tmp = x + (y * z)
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e+57) || !(y <= 2.4e-74)) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e+57) or not (y <= 2.4e-74): tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e+57) || !(y <= 2.4e-74)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e+57) || ~((y <= 2.4e-74))) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e+57], N[Not[LessEqual[y, 2.4e-74]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+57} \lor \neg \left(y \leq 2.4 \cdot 10^{-74}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if y < -3.39999999999999992e57 or 2.3999999999999999e-74 < y Initial program 100.0%
Taylor expanded in y around inf 90.6%
*-commutative90.6%
Simplified90.6%
if -3.39999999999999992e57 < y < 2.3999999999999999e-74Initial program 100.0%
Taylor expanded in x around inf 87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
sub-neg87.4%
distribute-rgt-in87.5%
*-un-lft-identity87.5%
distribute-lft-neg-in87.5%
unsub-neg87.5%
Applied egg-rr87.5%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.65e+57) (not (<= y 2.7e-74))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e+57) || !(y <= 2.7e-74)) {
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.65d+57)) .or. (.not. (y <= 2.7d-74))) 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.65e+57) || !(y <= 2.7e-74)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.65e+57) or not (y <= 2.7e-74): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.65e+57) || !(y <= 2.7e-74)) 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.65e+57) || ~((y <= 2.7e-74))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.65e+57], N[Not[LessEqual[y, 2.7e-74]], $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.65 \cdot 10^{+57} \lor \neg \left(y \leq 2.7 \cdot 10^{-74}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.64999999999999993e57 or 2.70000000000000018e-74 < y Initial program 100.0%
Taylor expanded in y around inf 90.6%
*-commutative90.6%
Simplified90.6%
if -2.64999999999999993e57 < y < 2.70000000000000018e-74Initial program 100.0%
Taylor expanded in x around inf 87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 8.5e-7))) (* x (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 8.5e-7)) {
tmp = 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 <= (-1.0d0)) .or. (.not. (z <= 8.5d-7))) then
tmp = 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 <= -1.0) || !(z <= 8.5e-7)) {
tmp = x * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 8.5e-7): tmp = x * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 8.5e-7)) tmp = Float64(x * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 8.5e-7))) tmp = x * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 8.5e-7]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 8.5 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 8.50000000000000014e-7 < z Initial program 100.0%
Taylor expanded in x around inf 47.1%
mul-1-neg47.1%
unsub-neg47.1%
Simplified47.1%
Taylor expanded in z around inf 46.1%
neg-mul-146.1%
Simplified46.1%
if -1 < z < 8.50000000000000014e-7Initial program 100.0%
Taylor expanded in z around 0 72.3%
Final simplification59.3%
(FPCore (x y z) :precision binary64 (if (<= z 5.8e+70) x (* x z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 5.8e+70) {
tmp = x;
} 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 <= 5.8d+70) then
tmp = x
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 5.8e+70) {
tmp = x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5.8e+70: tmp = x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5.8e+70) tmp = x; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 5.8e+70) tmp = x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5.8e+70], x, N[(x * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.8 \cdot 10^{+70}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < 5.7999999999999997e70Initial program 100.0%
Taylor expanded in z around 0 46.4%
if 5.7999999999999997e70 < z Initial program 100.0%
Taylor expanded in x around inf 46.7%
mul-1-neg46.7%
unsub-neg46.7%
Simplified46.7%
Taylor expanded in z around inf 46.7%
neg-mul-146.7%
Simplified46.7%
neg-sub046.7%
sub-neg46.7%
add-sqr-sqrt0.0%
sqrt-unprod19.5%
sqr-neg19.5%
sqrt-unprod13.9%
add-sqr-sqrt13.9%
Applied egg-rr13.9%
+-lft-identity13.9%
Simplified13.9%
(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 60.1%
mul-1-neg60.1%
unsub-neg60.1%
Simplified60.1%
(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.0%
herbie shell --seed 2024148
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))