
(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
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.1e+158)
(* x z)
(if (<= x -9.2e-34)
(* y x)
(if (<= x 5.8e-62) (- z) (if (<= x 2.6e+63) (* y x) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+158) {
tmp = x * z;
} else if (x <= -9.2e-34) {
tmp = y * x;
} else if (x <= 5.8e-62) {
tmp = -z;
} else if (x <= 2.6e+63) {
tmp = y * x;
} else {
tmp = 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 <= (-2.1d+158)) then
tmp = x * z
else if (x <= (-9.2d-34)) then
tmp = y * x
else if (x <= 5.8d-62) then
tmp = -z
else if (x <= 2.6d+63) then
tmp = y * x
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+158) {
tmp = x * z;
} else if (x <= -9.2e-34) {
tmp = y * x;
} else if (x <= 5.8e-62) {
tmp = -z;
} else if (x <= 2.6e+63) {
tmp = y * x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.1e+158: tmp = x * z elif x <= -9.2e-34: tmp = y * x elif x <= 5.8e-62: tmp = -z elif x <= 2.6e+63: tmp = y * x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.1e+158) tmp = Float64(x * z); elseif (x <= -9.2e-34) tmp = Float64(y * x); elseif (x <= 5.8e-62) tmp = Float64(-z); elseif (x <= 2.6e+63) tmp = Float64(y * x); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.1e+158) tmp = x * z; elseif (x <= -9.2e-34) tmp = y * x; elseif (x <= 5.8e-62) tmp = -z; elseif (x <= 2.6e+63) tmp = y * x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.1e+158], N[(x * z), $MachinePrecision], If[LessEqual[x, -9.2e-34], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.8e-62], (-z), If[LessEqual[x, 2.6e+63], N[(y * x), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+158}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -9.2 \cdot 10^{-34}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{-62}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+63}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.0999999999999999e158 or 2.6000000000000001e63 < x Initial program 90.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites92.3%
Taylor expanded in y around 0
Applied rewrites65.1%
if -2.0999999999999999e158 < x < -9.20000000000000045e-34 or 5.79999999999999971e-62 < x < 2.6000000000000001e63Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6488.4
Applied rewrites88.4%
Applied rewrites88.4%
Taylor expanded in y around 0
Applied rewrites23.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6466.4
Applied rewrites66.4%
if -9.20000000000000045e-34 < x < 5.79999999999999971e-62Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6473.2
Applied rewrites73.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -70000.0) (not (<= x 4.2e-44))) (* (+ z y) x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -70000.0) || !(x <= 4.2e-44)) {
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 <= (-70000.0d0)) .or. (.not. (x <= 4.2d-44))) 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 <= -70000.0) || !(x <= 4.2e-44)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -70000.0) or not (x <= 4.2e-44): tmp = (z + y) * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -70000.0) || !(x <= 4.2e-44)) 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 <= -70000.0) || ~((x <= 4.2e-44))) tmp = (z + y) * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -70000.0], N[Not[LessEqual[x, 4.2e-44]], $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 -70000 \lor \neg \left(x \leq 4.2 \cdot 10^{-44}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -7e4 or 4.20000000000000003e-44 < x Initial program 94.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.7
Applied rewrites97.7%
if -7e4 < x < 4.20000000000000003e-44Initial 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-+.f6472.2
Applied rewrites72.2%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.5e-129) (not (<= z 1.5e-108))) (* (+ -1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e-129) || !(z <= 1.5e-108)) {
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 <= (-7.5d-129)) .or. (.not. (z <= 1.5d-108))) 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 <= -7.5e-129) || !(z <= 1.5e-108)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.5e-129) or not (z <= 1.5e-108): tmp = (-1.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.5e-129) || !(z <= 1.5e-108)) 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 <= -7.5e-129) || ~((z <= 1.5e-108))) tmp = (-1.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.5e-129], N[Not[LessEqual[z, 1.5e-108]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-129} \lor \neg \left(z \leq 1.5 \cdot 10^{-108}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -7.49999999999999944e-129 or 1.49999999999999996e-108 < z Initial program 96.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-+.f6481.9
Applied rewrites81.9%
if -7.49999999999999944e-129 < z < 1.49999999999999996e-108Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6483.3
Applied rewrites83.3%
Applied rewrites83.4%
Taylor expanded in y around 0
Applied rewrites9.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6475.1
Applied rewrites75.1%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.1e+26) (not (<= x 9.2e-11))) (* x z) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.1e+26) || !(x <= 9.2e-11)) {
tmp = x * z;
} 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 <= (-6.1d+26)) .or. (.not. (x <= 9.2d-11))) then
tmp = x * z
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.1e+26) || !(x <= 9.2e-11)) {
tmp = x * z;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.1e+26) or not (x <= 9.2e-11): tmp = x * z else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.1e+26) || !(x <= 9.2e-11)) tmp = Float64(x * z); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.1e+26) || ~((x <= 9.2e-11))) tmp = x * z; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.1e+26], N[Not[LessEqual[x, 9.2e-11]], $MachinePrecision]], N[(x * z), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.1 \cdot 10^{+26} \lor \neg \left(x \leq 9.2 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.1000000000000003e26 or 9.20000000000000054e-11 < x Initial program 94.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites95.4%
Taylor expanded in y around 0
Applied rewrites51.6%
if -6.1000000000000003e26 < x < 9.20000000000000054e-11Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6468.1
Applied rewrites68.1%
Final simplification61.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.f6440.2
Applied rewrites40.2%
herbie shell --seed 2024342
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))