
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\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 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ y z) x (- z)))
double code(double x, double y, double z) {
return fma((y + z), x, -z);
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, -z\right)
\end{array}
Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= x -2.6e-66) (* y x) (if (<= x 3e-79) (- z) (if (<= x 3.5e+256) (* y x) (* z x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-66) {
tmp = y * x;
} else if (x <= 3e-79) {
tmp = -z;
} else if (x <= 3.5e+256) {
tmp = y * x;
} else {
tmp = z * 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 (x <= (-2.6d-66)) then
tmp = y * x
else if (x <= 3d-79) then
tmp = -z
else if (x <= 3.5d+256) then
tmp = y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-66) {
tmp = y * x;
} else if (x <= 3e-79) {
tmp = -z;
} else if (x <= 3.5e+256) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.6e-66: tmp = y * x elif x <= 3e-79: tmp = -z elif x <= 3.5e+256: tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.6e-66) tmp = Float64(y * x); elseif (x <= 3e-79) tmp = Float64(-z); elseif (x <= 3.5e+256) tmp = Float64(y * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.6e-66) tmp = y * x; elseif (x <= 3e-79) tmp = -z; elseif (x <= 3.5e+256) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.6e-66], N[(y * x), $MachinePrecision], If[LessEqual[x, 3e-79], (-z), If[LessEqual[x, 3.5e+256], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-66}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-79}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+256}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -2.5999999999999999e-66 or 3e-79 < x < 3.4999999999999998e256Initial program 97.2%
Taylor expanded in y around inf 61.3%
if -2.5999999999999999e-66 < x < 3e-79Initial program 99.9%
Taylor expanded in x around 0 80.0%
neg-mul-180.0%
Simplified80.0%
if 3.4999999999999998e256 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 82.3%
Final simplification69.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.0155))) (* (+ y z) x) (- (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0155)) {
tmp = (y + z) * x;
} else {
tmp = (y * 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 ((x <= (-1.0d0)) .or. (.not. (x <= 0.0155d0))) then
tmp = (y + z) * x
else
tmp = (y * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0155)) {
tmp = (y + z) * x;
} else {
tmp = (y * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 0.0155): tmp = (y + z) * x else: tmp = (y * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.0155)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(y * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.0155))) tmp = (y + z) * x; else tmp = (y * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.0155]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.0155\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x - z\\
\end{array}
\end{array}
if x < -1 or 0.0155 < x Initial program 96.8%
Taylor expanded in x around inf 99.5%
+-commutative99.5%
Simplified99.5%
if -1 < x < 0.0155Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.9e-65) (not (<= x 4.8e-79))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-65) || !(x <= 4.8e-79)) {
tmp = (y + z) * x;
} else {
tmp = -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.9d-65)) .or. (.not. (x <= 4.8d-79))) then
tmp = (y + z) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-65) || !(x <= 4.8e-79)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.9e-65) or not (x <= 4.8e-79): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.9e-65) || !(x <= 4.8e-79)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.9e-65) || ~((x <= 4.8e-79))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.9e-65], N[Not[LessEqual[x, 4.8e-79]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-65} \lor \neg \left(x \leq 4.8 \cdot 10^{-79}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.89999999999999964e-65 or 4.80000000000000011e-79 < x Initial program 97.4%
Taylor expanded in x around inf 91.8%
+-commutative91.8%
Simplified91.8%
if -4.89999999999999964e-65 < x < 4.80000000000000011e-79Initial program 99.9%
Taylor expanded in x around 0 80.0%
neg-mul-180.0%
Simplified80.0%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-63) (not (<= x 4e-80))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-63) || !(x <= 4e-80)) {
tmp = y * x;
} else {
tmp = -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 <= (-3.1d-63)) .or. (.not. (x <= 4d-80))) then
tmp = y * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-63) || !(x <= 4e-80)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-63) or not (x <= 4e-80): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-63) || !(x <= 4e-80)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.1e-63) || ~((x <= 4e-80))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-63], N[Not[LessEqual[x, 4e-80]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-63} \lor \neg \left(x \leq 4 \cdot 10^{-80}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.09999999999999984e-63 or 3.99999999999999985e-80 < x Initial program 97.4%
Taylor expanded in y around inf 59.6%
if -3.09999999999999984e-63 < x < 3.99999999999999985e-80Initial program 99.9%
Taylor expanded in x around 0 80.0%
neg-mul-180.0%
Simplified80.0%
Final simplification67.5%
(FPCore (x y z) :precision binary64 (- (* (+ y z) x) z))
double code(double x, double y, double z) {
return ((y + z) * 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 = ((y + z) * x) - z
end function
public static double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
def code(x, y, z): return ((y + z) * x) - z
function code(x, y, z) return Float64(Float64(Float64(y + z) * x) - z) end
function tmp = code(x, y, z) tmp = ((y + z) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + z\right) \cdot x - z
\end{array}
Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.4%
Taylor expanded in x around 0 37.0%
neg-mul-137.0%
Simplified37.0%
herbie shell --seed 2024135
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))