
(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 6 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 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
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 -1.65e+82)
(* z x)
(if (<= x -1.72e-59)
(* y x)
(if (<= x 4.8e-17)
(- z)
(if (or (<= x 2.45e+48) (not (<= x 2.7e+139))) (* y x) (* z x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+82) {
tmp = z * x;
} else if (x <= -1.72e-59) {
tmp = y * x;
} else if (x <= 4.8e-17) {
tmp = -z;
} else if ((x <= 2.45e+48) || !(x <= 2.7e+139)) {
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 <= (-1.65d+82)) then
tmp = z * x
else if (x <= (-1.72d-59)) then
tmp = y * x
else if (x <= 4.8d-17) then
tmp = -z
else if ((x <= 2.45d+48) .or. (.not. (x <= 2.7d+139))) 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 <= -1.65e+82) {
tmp = z * x;
} else if (x <= -1.72e-59) {
tmp = y * x;
} else if (x <= 4.8e-17) {
tmp = -z;
} else if ((x <= 2.45e+48) || !(x <= 2.7e+139)) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e+82: tmp = z * x elif x <= -1.72e-59: tmp = y * x elif x <= 4.8e-17: tmp = -z elif (x <= 2.45e+48) or not (x <= 2.7e+139): tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e+82) tmp = Float64(z * x); elseif (x <= -1.72e-59) tmp = Float64(y * x); elseif (x <= 4.8e-17) tmp = Float64(-z); elseif ((x <= 2.45e+48) || !(x <= 2.7e+139)) 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 <= -1.65e+82) tmp = z * x; elseif (x <= -1.72e-59) tmp = y * x; elseif (x <= 4.8e-17) tmp = -z; elseif ((x <= 2.45e+48) || ~((x <= 2.7e+139))) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e+82], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.72e-59], N[(y * x), $MachinePrecision], If[LessEqual[x, 4.8e-17], (-z), If[Or[LessEqual[x, 2.45e+48], N[Not[LessEqual[x, 2.7e+139]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+82}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -1.72 \cdot 10^{-59}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-17}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.45 \cdot 10^{+48} \lor \neg \left(x \leq 2.7 \cdot 10^{+139}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -1.6499999999999999e82 or 2.45000000000000015e48 < x < 2.6999999999999998e139Initial program 91.8%
*-commutative91.8%
sub-neg91.8%
distribute-rgt-in91.8%
metadata-eval91.8%
neg-mul-191.8%
associate-+r+91.8%
unsub-neg91.8%
+-commutative91.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 66.3%
Taylor expanded in x around inf 66.3%
if -1.6499999999999999e82 < x < -1.72e-59 or 4.79999999999999973e-17 < x < 2.45000000000000015e48 or 2.6999999999999998e139 < x Initial program 97.2%
Taylor expanded in y around inf 65.7%
if -1.72e-59 < x < 4.79999999999999973e-17Initial program 100.0%
Taylor expanded in x around 0 75.7%
neg-mul-175.7%
Simplified75.7%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e-66) (not (<= x 3.4e-17))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-66) || !(x <= 3.4e-17)) {
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 <= (-1.4d-66)) .or. (.not. (x <= 3.4d-17))) 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 <= -1.4e-66) || !(x <= 3.4e-17)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e-66) or not (x <= 3.4e-17): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e-66) || !(x <= 3.4e-17)) 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 <= -1.4e-66) || ~((x <= 3.4e-17))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e-66], N[Not[LessEqual[x, 3.4e-17]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-66} \lor \neg \left(x \leq 3.4 \cdot 10^{-17}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.4e-66 or 3.3999999999999998e-17 < x Initial program 94.8%
Taylor expanded in x around inf 94.3%
+-commutative94.3%
Simplified94.3%
if -1.4e-66 < x < 3.3999999999999998e-17Initial program 100.0%
Taylor expanded in x around 0 75.7%
neg-mul-175.7%
Simplified75.7%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e-66) (not (<= x 1e-18))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e-66) || !(x <= 1e-18)) {
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 <= (-7.5d-66)) .or. (.not. (x <= 1d-18))) 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 <= -7.5e-66) || !(x <= 1e-18)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e-66) or not (x <= 1e-18): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e-66) || !(x <= 1e-18)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.5e-66) || ~((x <= 1e-18))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-66], N[Not[LessEqual[x, 1e-18]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-66} \lor \neg \left(x \leq 10^{-18}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.49999999999999995e-66 or 1.0000000000000001e-18 < x Initial program 94.8%
Taylor expanded in y around inf 54.1%
if -7.49999999999999995e-66 < x < 1.0000000000000001e-18Initial program 100.0%
Taylor expanded in x around 0 75.7%
neg-mul-175.7%
Simplified75.7%
Final simplification64.4%
(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 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
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 97.2%
Taylor expanded in x around 0 40.4%
neg-mul-140.4%
Simplified40.4%
herbie shell --seed 2024091
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))