
(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 (if (or (<= y -5.5e+94) (not (<= y 0.00017))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e+94) || !(y <= 0.00017)) {
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 ((y <= (-5.5d+94)) .or. (.not. (y <= 0.00017d0))) 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 ((y <= -5.5e+94) || !(y <= 0.00017)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e+94) or not (y <= 0.00017): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e+94) || !(y <= 0.00017)) 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 ((y <= -5.5e+94) || ~((y <= 0.00017))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e+94], N[Not[LessEqual[y, 0.00017]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+94} \lor \neg \left(y \leq 0.00017\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.4999999999999997e94 or 1.7e-4 < y Initial program 100.0%
Taylor expanded in z around inf 84.3%
if -5.4999999999999997e94 < y < 1.7e-4Initial program 100.0%
*-commutative100.0%
flip--81.0%
associate-*r/76.5%
+-commutative76.5%
Applied egg-rr76.5%
associate-/l*80.9%
difference-of-squares80.9%
+-commutative80.9%
associate-/r*99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 87.6%
mul-1-neg87.6%
sub-neg87.6%
Simplified87.6%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.3e-8))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.3e-8)) {
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.3d-8))) 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.3e-8)) {
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.3e-8): 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.3e-8)) 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.3e-8))) 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.3e-8]], $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.3 \cdot 10^{-8}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1.3000000000000001e-8 < z Initial program 100.0%
Taylor expanded in z around inf 97.8%
if -1 < z < 1.3000000000000001e-8Initial program 100.0%
*-commutative100.0%
flip--59.4%
associate-*r/57.6%
+-commutative57.6%
Applied egg-rr57.6%
associate-/l*59.4%
difference-of-squares59.7%
+-commutative59.7%
associate-/r*99.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in y around inf 99.4%
*-commutative99.4%
Simplified99.4%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (<= y -9.8e+94) (* y z) (if (<= y 9.6e+34) (* x (- 1.0 z)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.8e+94) {
tmp = y * z;
} else if (y <= 9.6e+34) {
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 (y <= (-9.8d+94)) then
tmp = y * z
else if (y <= 9.6d+34) 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 (y <= -9.8e+94) {
tmp = y * z;
} else if (y <= 9.6e+34) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.8e+94: tmp = y * z elif y <= 9.6e+34: tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.8e+94) tmp = Float64(y * z); elseif (y <= 9.6e+34) 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 (y <= -9.8e+94) tmp = y * z; elseif (y <= 9.6e+34) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.8e+94], N[(y * z), $MachinePrecision], If[LessEqual[y, 9.6e+34], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{+94}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{+34}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -9.7999999999999998e94 or 9.59999999999999948e34 < y Initial program 100.0%
Taylor expanded in x around 0 76.8%
if -9.7999999999999998e94 < y < 9.59999999999999948e34Initial program 100.0%
*-commutative100.0%
flip--81.6%
associate-*r/77.4%
+-commutative77.4%
Applied egg-rr77.4%
associate-/l*81.5%
difference-of-squares81.5%
+-commutative81.5%
associate-/r*99.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in x around inf 87.0%
mul-1-neg87.0%
sub-neg87.0%
Simplified87.0%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (<= y -4.6e+94) (* y z) (if (<= y 700.0) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.6e+94) {
tmp = y * z;
} else if (y <= 700.0) {
tmp = x;
} 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 (y <= (-4.6d+94)) then
tmp = y * z
else if (y <= 700.0d0) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.6e+94) {
tmp = y * z;
} else if (y <= 700.0) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.6e+94: tmp = y * z elif y <= 700.0: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.6e+94) tmp = Float64(y * z); elseif (y <= 700.0) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.6e+94) tmp = y * z; elseif (y <= 700.0) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.6e+94], N[(y * z), $MachinePrecision], If[LessEqual[y, 700.0], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{+94}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 700:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.5999999999999999e94 or 700 < y Initial program 100.0%
Taylor expanded in x around 0 75.4%
if -4.5999999999999999e94 < y < 700Initial program 100.0%
Taylor expanded in z around 0 46.1%
Final simplification57.5%
(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 2023293
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))