
(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 (+ 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 97.6%
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 -5.6e-11) (not (<= x 6.4e-6))) (* (+ z y) x) (fma z x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-11) || !(x <= 6.4e-6)) {
tmp = (z + y) * x;
} else {
tmp = fma(z, x, -z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-11) || !(x <= 6.4e-6)) tmp = Float64(Float64(z + y) * x); else tmp = fma(z, x, Float64(-z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-11], N[Not[LessEqual[x, 6.4e-6]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(z * x + (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-11} \lor \neg \left(x \leq 6.4 \cdot 10^{-6}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, -z\right)\\
\end{array}
\end{array}
if x < -5.6e-11 or 6.3999999999999997e-6 < x Initial program 95.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.3
Applied rewrites98.3%
if -5.6e-11 < x < 6.3999999999999997e-6Initial 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-+.f6478.7
Applied rewrites78.7%
Applied rewrites78.7%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e-11) (not (<= x 6.4e-6))) (* (+ z y) x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-11) || !(x <= 6.4e-6)) {
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 <= (-5.6d-11)) .or. (.not. (x <= 6.4d-6))) 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 <= -5.6e-11) || !(x <= 6.4e-6)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e-11) or not (x <= 6.4e-6): tmp = (z + y) * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-11) || !(x <= 6.4e-6)) 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 <= -5.6e-11) || ~((x <= 6.4e-6))) tmp = (z + y) * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-11], N[Not[LessEqual[x, 6.4e-6]], $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 -5.6 \cdot 10^{-11} \lor \neg \left(x \leq 6.4 \cdot 10^{-6}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -5.6e-11 or 6.3999999999999997e-6 < x Initial program 95.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.3
Applied rewrites98.3%
if -5.6e-11 < x < 6.3999999999999997e-6Initial 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-+.f6478.7
Applied rewrites78.7%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.3e-88) (not (<= z 1.02e-154))) (* (+ -1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.3e-88) || !(z <= 1.02e-154)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * 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 <= (-4.3d-88)) .or. (.not. (z <= 1.02d-154))) then
tmp = ((-1.0d0) + x) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.3e-88) || !(z <= 1.02e-154)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.3e-88) or not (z <= 1.02e-154): tmp = (-1.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.3e-88) || !(z <= 1.02e-154)) tmp = Float64(Float64(-1.0 + x) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.3e-88) || ~((z <= 1.02e-154))) tmp = (-1.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.3e-88], N[Not[LessEqual[z, 1.02e-154]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{-88} \lor \neg \left(z \leq 1.02 \cdot 10^{-154}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -4.2999999999999997e-88 or 1.01999999999999992e-154 < z Initial program 96.7%
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.1
Applied rewrites83.1%
if -4.2999999999999997e-88 < z < 1.01999999999999992e-154Initial program 99.9%
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-+.f6429.5
Applied rewrites29.5%
Applied rewrites29.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6470.7
Applied rewrites70.7%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.8e-11) (not (<= x 2.5e-7))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.8e-11) || !(x <= 2.5e-7)) {
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 <= (-1.8d-11)) .or. (.not. (x <= 2.5d-7))) 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 <= -1.8e-11) || !(x <= 2.5e-7)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.8e-11) or not (x <= 2.5e-7): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.8e-11) || !(x <= 2.5e-7)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.8e-11) || ~((x <= 2.5e-7))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.8e-11], N[Not[LessEqual[x, 2.5e-7]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-11} \lor \neg \left(x \leq 2.5 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.79999999999999992e-11 or 2.49999999999999989e-7 < x Initial program 95.4%
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-+.f6457.4
Applied rewrites57.4%
Applied rewrites57.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6448.7
Applied rewrites48.7%
if -1.79999999999999992e-11 < x < 2.49999999999999989e-7Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6478.0
Applied rewrites78.0%
Final simplification63.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.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6439.9
Applied rewrites39.9%
herbie shell --seed 2024338
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))