
(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 (if (or (<= x -4.3e+46) (not (<= x 1.05e+27))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e+46) || !(x <= 1.05e+27)) {
tmp = x * (1.0 - 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 ((x <= (-4.3d+46)) .or. (.not. (x <= 1.05d+27))) then
tmp = x * (1.0d0 - 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 ((x <= -4.3e+46) || !(x <= 1.05e+27)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.3e+46) or not (x <= 1.05e+27): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.3e+46) || !(x <= 1.05e+27)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.3e+46) || ~((x <= 1.05e+27))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.3e+46], N[Not[LessEqual[x, 1.05e+27]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{+46} \lor \neg \left(x \leq 1.05 \cdot 10^{+27}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -4.30000000000000005e46 or 1.04999999999999997e27 < x Initial program 100.0%
Taylor expanded in x around inf 89.7%
mul-1-neg89.7%
unsub-neg89.7%
Simplified89.7%
if -4.30000000000000005e46 < x < 1.04999999999999997e27Initial program 100.0%
Taylor expanded in y around inf 88.8%
*-commutative88.8%
Simplified88.8%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (<= x -2.9e+50) (- x (* x z)) (if (<= x 1.2e+27) (+ x (* y z)) (* x (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.9e+50) {
tmp = x - (x * z);
} else if (x <= 1.2e+27) {
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 (x <= (-2.9d+50)) then
tmp = x - (x * z)
else if (x <= 1.2d+27) 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 (x <= -2.9e+50) {
tmp = x - (x * z);
} else if (x <= 1.2e+27) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.9e+50: tmp = x - (x * z) elif x <= 1.2e+27: tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.9e+50) tmp = Float64(x - Float64(x * z)); elseif (x <= 1.2e+27) 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 (x <= -2.9e+50) tmp = x - (x * z); elseif (x <= 1.2e+27) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.9e+50], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.2e+27], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+50}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+27}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if x < -2.9e50Initial program 100.0%
Taylor expanded in x around inf 91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
sub-neg91.3%
distribute-rgt-in91.3%
*-un-lft-identity91.3%
distribute-lft-neg-in91.3%
unsub-neg91.3%
*-commutative91.3%
Applied egg-rr91.3%
if -2.9e50 < x < 1.19999999999999999e27Initial program 100.0%
Taylor expanded in y around inf 88.8%
*-commutative88.8%
Simplified88.8%
if 1.19999999999999999e27 < x Initial program 100.0%
Taylor expanded in x around inf 88.0%
mul-1-neg88.0%
unsub-neg88.0%
Simplified88.0%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1860.0))) (* x (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1860.0)) {
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 <= 1860.0d0))) 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 <= 1860.0)) {
tmp = x * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1860.0): tmp = x * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1860.0)) 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 <= 1860.0))) 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, 1860.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1860\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1860 < 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.3%
mul-1-neg46.3%
*-commutative46.3%
distribute-rgt-neg-in46.3%
Simplified46.3%
if -1 < z < 1860Initial program 100.0%
Taylor expanded in z around 0 68.1%
Final simplification56.4%
(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 (- 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 57.2%
mul-1-neg57.2%
unsub-neg57.2%
Simplified57.2%
Final simplification57.2%
(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 32.8%
Final simplification32.8%
herbie shell --seed 2024080
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))