
(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 (+ 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.2%
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 (<= x -4.6e+140) (* z x) (if (or (<= x -6.2e-15) (not (<= x 3e-109))) (* y x) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.6e+140) {
tmp = z * x;
} else if ((x <= -6.2e-15) || !(x <= 3e-109)) {
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 <= (-4.6d+140)) then
tmp = z * x
else if ((x <= (-6.2d-15)) .or. (.not. (x <= 3d-109))) 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 <= -4.6e+140) {
tmp = z * x;
} else if ((x <= -6.2e-15) || !(x <= 3e-109)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.6e+140: tmp = z * x elif (x <= -6.2e-15) or not (x <= 3e-109): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.6e+140) tmp = Float64(z * x); elseif ((x <= -6.2e-15) || !(x <= 3e-109)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.6e+140) tmp = z * x; elseif ((x <= -6.2e-15) || ~((x <= 3e-109))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.6e+140], N[(z * x), $MachinePrecision], If[Or[LessEqual[x, -6.2e-15], N[Not[LessEqual[x, 3e-109]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{+140}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -6.2 \cdot 10^{-15} \lor \neg \left(x \leq 3 \cdot 10^{-109}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.59999999999999981e140Initial program 94.1%
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-+.f6465.8
Applied rewrites65.8%
Taylor expanded in x around inf
Applied rewrites65.8%
if -4.59999999999999981e140 < x < -6.1999999999999998e-15 or 3.00000000000000021e-109 < x Initial program 95.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%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6462.3
Applied rewrites62.3%
if -6.1999999999999998e-15 < x < 3.00000000000000021e-109Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6482.4
Applied rewrites82.4%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-15) (not (<= x 3e-109))) (* (+ z y) x) (fma z x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-15) || !(x <= 3e-109)) {
tmp = (z + y) * x;
} else {
tmp = fma(z, x, -z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-15) || !(x <= 3e-109)) 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, -6.2e-15], N[Not[LessEqual[x, 3e-109]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(z * x + (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-15} \lor \neg \left(x \leq 3 \cdot 10^{-109}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, -z\right)\\
\end{array}
\end{array}
if x < -6.1999999999999998e-15 or 3.00000000000000021e-109 < x Initial program 95.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6495.3
Applied rewrites95.3%
if -6.1999999999999998e-15 < x < 3.00000000000000021e-109Initial 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-+.f6482.4
Applied rewrites82.4%
Applied rewrites82.5%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-15) (not (<= x 3e-109))) (* (+ z y) x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-15) || !(x <= 3e-109)) {
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 <= (-6.2d-15)) .or. (.not. (x <= 3d-109))) 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 <= -6.2e-15) || !(x <= 3e-109)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-15) or not (x <= 3e-109): tmp = (z + y) * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-15) || !(x <= 3e-109)) 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 <= -6.2e-15) || ~((x <= 3e-109))) tmp = (z + y) * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-15], N[Not[LessEqual[x, 3e-109]], $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 -6.2 \cdot 10^{-15} \lor \neg \left(x \leq 3 \cdot 10^{-109}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -6.1999999999999998e-15 or 3.00000000000000021e-109 < x Initial program 95.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6495.3
Applied rewrites95.3%
if -6.1999999999999998e-15 < x < 3.00000000000000021e-109Initial 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-+.f6482.4
Applied rewrites82.4%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.9e-85) (not (<= z 2.6e-97))) (* (+ -1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.9e-85) || !(z <= 2.6e-97)) {
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 <= (-3.9d-85)) .or. (.not. (z <= 2.6d-97))) 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 <= -3.9e-85) || !(z <= 2.6e-97)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.9e-85) or not (z <= 2.6e-97): tmp = (-1.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.9e-85) || !(z <= 2.6e-97)) 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 <= -3.9e-85) || ~((z <= 2.6e-97))) tmp = (-1.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.9e-85], N[Not[LessEqual[z, 2.6e-97]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.9 \cdot 10^{-85} \lor \neg \left(z \leq 2.6 \cdot 10^{-97}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -3.89999999999999988e-85 or 2.60000000000000007e-97 < z Initial program 95.8%
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-+.f6479.4
Applied rewrites79.4%
if -3.89999999999999988e-85 < z < 2.60000000000000007e-97Initial program 100.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%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6475.6
Applied rewrites75.6%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -3250.0) (not (<= x 1.0))) (* z x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3250.0) || !(x <= 1.0)) {
tmp = 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 <= (-3250.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 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 <= -3250.0) || !(x <= 1.0)) {
tmp = z * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3250.0) or not (x <= 1.0): tmp = z * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3250.0) || !(x <= 1.0)) tmp = Float64(z * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3250.0) || ~((x <= 1.0))) tmp = z * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3250.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3250 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3250 or 1 < x Initial program 94.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-+.f6450.4
Applied rewrites50.4%
Taylor expanded in x around inf
Applied rewrites50.0%
if -3250 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6472.7
Applied rewrites72.7%
Final simplification60.9%
(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
mul-1-negN/A
lower-neg.f6436.4
Applied rewrites36.4%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))