
(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 6 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.8e-63)
(not (or (<= x 1.2e-104) (and (not (<= x 3.5e-76)) (<= x 1.44e-5)))))
(* x (- 1.0 z))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-63) || !((x <= 1.2e-104) || (!(x <= 3.5e-76) && (x <= 1.44e-5)))) {
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 <= (-4.8d-63)) .or. (.not. (x <= 1.2d-104) .or. (.not. (x <= 3.5d-76)) .and. (x <= 1.44d-5))) 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 <= -4.8e-63) || !((x <= 1.2e-104) || (!(x <= 3.5e-76) && (x <= 1.44e-5)))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-63) or not ((x <= 1.2e-104) or (not (x <= 3.5e-76) and (x <= 1.44e-5))): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-63) || !((x <= 1.2e-104) || (!(x <= 3.5e-76) && (x <= 1.44e-5)))) 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 <= -4.8e-63) || ~(((x <= 1.2e-104) || (~((x <= 3.5e-76)) && (x <= 1.44e-5))))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-63], N[Not[Or[LessEqual[x, 1.2e-104], And[N[Not[LessEqual[x, 3.5e-76]], $MachinePrecision], LessEqual[x, 1.44e-5]]]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-63} \lor \neg \left(x \leq 1.2 \cdot 10^{-104} \lor \neg \left(x \leq 3.5 \cdot 10^{-76}\right) \land x \leq 1.44 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.8000000000000001e-63 or 1.2e-104 < x < 3.49999999999999997e-76 or 1.43999999999999993e-5 < x Initial program 100.0%
Taylor expanded in x around inf 88.5%
mul-1-neg88.5%
unsub-neg88.5%
Simplified88.5%
if -4.8000000000000001e-63 < x < 1.2e-104 or 3.49999999999999997e-76 < x < 1.43999999999999993e-5Initial program 100.0%
Taylor expanded in y around inf 93.3%
*-commutative93.3%
Simplified93.3%
Taylor expanded in x around 0 78.9%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -490000.0) (not (<= x 1.46e+51))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -490000.0) || !(x <= 1.46e+51)) {
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 <= (-490000.0d0)) .or. (.not. (x <= 1.46d+51))) 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 <= -490000.0) || !(x <= 1.46e+51)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -490000.0) or not (x <= 1.46e+51): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -490000.0) || !(x <= 1.46e+51)) 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 <= -490000.0) || ~((x <= 1.46e+51))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -490000.0], N[Not[LessEqual[x, 1.46e+51]], $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 -490000 \lor \neg \left(x \leq 1.46 \cdot 10^{+51}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -4.9e5 or 1.4600000000000001e51 < x Initial program 100.0%
Taylor expanded in x around inf 92.5%
mul-1-neg92.5%
unsub-neg92.5%
Simplified92.5%
if -4.9e5 < x < 1.4600000000000001e51Initial program 100.0%
Taylor expanded in y around inf 89.1%
*-commutative89.1%
Simplified89.1%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.4e-80) (not (<= z 2.35e-35))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.4e-80) || !(z <= 2.35e-35)) {
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 <= (-9.4d-80)) .or. (.not. (z <= 2.35d-35))) 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 <= -9.4e-80) || !(z <= 2.35e-35)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.4e-80) or not (z <= 2.35e-35): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.4e-80) || !(z <= 2.35e-35)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9.4e-80) || ~((z <= 2.35e-35))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.4e-80], N[Not[LessEqual[z, 2.35e-35]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.4 \cdot 10^{-80} \lor \neg \left(z \leq 2.35 \cdot 10^{-35}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.39999999999999945e-80 or 2.35e-35 < z Initial program 100.0%
Taylor expanded in y around inf 59.6%
*-commutative59.6%
Simplified59.6%
Taylor expanded in x around 0 54.0%
if -9.39999999999999945e-80 < z < 2.35e-35Initial program 100.0%
Taylor expanded in z around 0 79.9%
Final simplification64.0%
(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 35.7%
Final simplification35.7%
herbie shell --seed 2024044
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))