
(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 98.4%
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 -1.0) (* z x) (if (<= x 7.5e-57) (- z) (if (<= x 1.45e+139) (* y x) (* z x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = z * x;
} else if (x <= 7.5e-57) {
tmp = -z;
} else if (x <= 1.45e+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.0d0)) then
tmp = z * x
else if (x <= 7.5d-57) then
tmp = -z
else if (x <= 1.45d+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.0) {
tmp = z * x;
} else if (x <= 7.5e-57) {
tmp = -z;
} else if (x <= 1.45e+139) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = z * x elif x <= 7.5e-57: tmp = -z elif x <= 1.45e+139: tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(z * x); elseif (x <= 7.5e-57) tmp = Float64(-z); elseif (x <= 1.45e+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.0) tmp = z * x; elseif (x <= 7.5e-57) tmp = -z; elseif (x <= 1.45e+139) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 7.5e-57], (-z), If[LessEqual[x, 1.45e+139], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-57}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+139}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -1 or 1.4499999999999999e139 < x Initial program 96.2%
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-+.f6464.4
Applied rewrites64.4%
Taylor expanded in x around inf
Applied rewrites63.8%
if -1 < x < 7.49999999999999973e-57Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6469.3
Applied rewrites69.3%
if 7.49999999999999973e-57 < x < 1.4499999999999999e139Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6413.1
Applied rewrites13.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6454.9
Applied rewrites54.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-45) (not (<= z 2.25e-68))) (fma z x (- z)) (* (+ z y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-45) || !(z <= 2.25e-68)) {
tmp = fma(z, x, -z);
} else {
tmp = (z + y) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -3e-45) || !(z <= 2.25e-68)) tmp = fma(z, x, Float64(-z)); else tmp = Float64(Float64(z + y) * x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-45], N[Not[LessEqual[z, 2.25e-68]], $MachinePrecision]], N[(z * x + (-z)), $MachinePrecision], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-45} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\right):\\
\;\;\;\;\mathsf{fma}\left(z, x, -z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) \cdot x\\
\end{array}
\end{array}
if z < -3.00000000000000011e-45 or 2.25e-68 < z Initial program 97.5%
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-+.f6486.5
Applied rewrites86.5%
Applied rewrites86.5%
if -3.00000000000000011e-45 < z < 2.25e-68Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6486.9
Applied rewrites86.9%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-45) (not (<= z 2.25e-68))) (* (+ -1.0 x) z) (* (+ z y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-45) || !(z <= 2.25e-68)) {
tmp = (-1.0 + x) * z;
} else {
tmp = (z + 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 <= (-3d-45)) .or. (.not. (z <= 2.25d-68))) then
tmp = ((-1.0d0) + x) * z
else
tmp = (z + y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-45) || !(z <= 2.25e-68)) {
tmp = (-1.0 + x) * z;
} else {
tmp = (z + y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-45) or not (z <= 2.25e-68): tmp = (-1.0 + x) * z else: tmp = (z + y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e-45) || !(z <= 2.25e-68)) tmp = Float64(Float64(-1.0 + x) * z); else tmp = Float64(Float64(z + y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e-45) || ~((z <= 2.25e-68))) tmp = (-1.0 + x) * z; else tmp = (z + y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-45], N[Not[LessEqual[z, 2.25e-68]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-45} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) \cdot x\\
\end{array}
\end{array}
if z < -3.00000000000000011e-45 or 2.25e-68 < z Initial program 97.5%
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-+.f6486.5
Applied rewrites86.5%
if -3.00000000000000011e-45 < z < 2.25e-68Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6486.9
Applied rewrites86.9%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-55) (not (<= z 2.25e-68))) (* (+ -1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-55) || !(z <= 2.25e-68)) {
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.5d-55)) .or. (.not. (z <= 2.25d-68))) 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.5e-55) || !(z <= 2.25e-68)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e-55) or not (z <= 2.25e-68): tmp = (-1.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-55) || !(z <= 2.25e-68)) 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.5e-55) || ~((z <= 2.25e-68))) tmp = (-1.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e-55], N[Not[LessEqual[z, 2.25e-68]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-55} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -3.50000000000000025e-55 or 2.25e-68 < z Initial program 97.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-+.f6486.1
Applied rewrites86.1%
if -3.50000000000000025e-55 < z < 2.25e-68Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6415.9
Applied rewrites15.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6478.6
Applied rewrites78.6%
Final simplification83.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* z x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.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 <= (-1.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 <= -1.0) || !(x <= 1.0)) {
tmp = z * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = z * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.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 <= -1.0) || ~((x <= 1.0))) tmp = z * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 97.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-+.f6460.9
Applied rewrites60.9%
Taylor expanded in x around inf
Applied rewrites59.8%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6467.0
Applied rewrites67.0%
Final simplification63.2%
(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 98.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6433.2
Applied rewrites33.2%
herbie shell --seed 2024320
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))