
(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 5 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 (+ z y) x (- z)))
double code(double x, double y, double z) {
return fma((z + y), x, -z);
}
function code(x, y, z) return fma(Float64(z + y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(z + y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + y, x, -z\right)
\end{array}
Initial program 96.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.46e-89) (not (<= x 2.35e-48))) (* (+ z y) x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.46e-89) || !(x <= 2.35e-48)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + 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.46d-89)) .or. (.not. (x <= 2.35d-48))) then
tmp = (z + y) * x
else
tmp = ((-1.0d0) + x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.46e-89) || !(x <= 2.35e-48)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.46e-89) or not (x <= 2.35e-48): tmp = (z + y) * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.46e-89) || !(x <= 2.35e-48)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(-1.0 + x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.46e-89) || ~((x <= 2.35e-48))) tmp = (z + y) * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.46e-89], N[Not[LessEqual[x, 2.35e-48]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.46 \cdot 10^{-89} \lor \neg \left(x \leq 2.35 \cdot 10^{-48}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -1.46e-89 or 2.3499999999999999e-48 < x Initial program 94.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6493.6
Applied rewrites93.6%
if -1.46e-89 < x < 2.3499999999999999e-48Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6473.2
Applied rewrites73.2%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-80) (not (<= z 1.24e-60))) (* (+ -1.0 x) z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-80) || !(z <= 1.24e-60)) {
tmp = (-1.0 + x) * z;
} else {
tmp = x * y;
}
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 <= (-6.5d-80)) .or. (.not. (z <= 1.24d-60))) then
tmp = ((-1.0d0) + x) * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-80) || !(z <= 1.24e-60)) {
tmp = (-1.0 + x) * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-80) or not (z <= 1.24e-60): tmp = (-1.0 + x) * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-80) || !(z <= 1.24e-60)) tmp = Float64(Float64(-1.0 + x) * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.5e-80) || ~((z <= 1.24e-60))) tmp = (-1.0 + x) * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-80], N[Not[LessEqual[z, 1.24e-60]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-80} \lor \neg \left(z \leq 1.24 \cdot 10^{-60}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -6.49999999999999984e-80 or 1.23999999999999998e-60 < z Initial program 94.6%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6483.7
Applied rewrites83.7%
if -6.49999999999999984e-80 < z < 1.23999999999999998e-60Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Applied rewrites99.9%
Taylor expanded in y around inf
Applied rewrites70.0%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e-89) (not (<= x 2.05e-53))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e-89) || !(x <= 2.05e-53)) {
tmp = x * y;
} 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.75d-89)) .or. (.not. (x <= 2.05d-53))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e-89) || !(x <= 2.05e-53)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.75e-89) or not (x <= 2.05e-53): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e-89) || !(x <= 2.05e-53)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.75e-89) || ~((x <= 2.05e-53))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e-89], N[Not[LessEqual[x, 2.05e-53]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-89} \lor \neg \left(x \leq 2.05 \cdot 10^{-53}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.74999999999999985e-89 or 2.05e-53 < x Initial program 95.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites51.8%
if -1.74999999999999985e-89 < x < 2.05e-53Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6473.7
Applied rewrites73.7%
Final simplification60.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 96.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6433.5
Applied rewrites33.5%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))