
(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 x (+ y z) (- z)))
double code(double x, double y, double z) {
return fma(x, (y + z), -z);
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, -z\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
distribute-lft-out100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.18e+219)
(* x z)
(if (<= x -7.6e-15)
(* x y)
(if (<= x 3.1e-17) (- z) (if (<= x 1.25e+157) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.18e+219) {
tmp = x * z;
} else if (x <= -7.6e-15) {
tmp = x * y;
} else if (x <= 3.1e-17) {
tmp = -z;
} else if (x <= 1.25e+157) {
tmp = x * y;
} 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 <= (-1.18d+219)) then
tmp = x * z
else if (x <= (-7.6d-15)) then
tmp = x * y
else if (x <= 3.1d-17) then
tmp = -z
else if (x <= 1.25d+157) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.18e+219) {
tmp = x * z;
} else if (x <= -7.6e-15) {
tmp = x * y;
} else if (x <= 3.1e-17) {
tmp = -z;
} else if (x <= 1.25e+157) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.18e+219: tmp = x * z elif x <= -7.6e-15: tmp = x * y elif x <= 3.1e-17: tmp = -z elif x <= 1.25e+157: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.18e+219) tmp = Float64(x * z); elseif (x <= -7.6e-15) tmp = Float64(x * y); elseif (x <= 3.1e-17) tmp = Float64(-z); elseif (x <= 1.25e+157) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.18e+219) tmp = x * z; elseif (x <= -7.6e-15) tmp = x * y; elseif (x <= 3.1e-17) tmp = -z; elseif (x <= 1.25e+157) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.18e+219], N[(x * z), $MachinePrecision], If[LessEqual[x, -7.6e-15], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.1e-17], (-z), If[LessEqual[x, 1.25e+157], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.18 \cdot 10^{+219}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7.6 \cdot 10^{-15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-17}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+157}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.18e219 or 1.24999999999999994e157 < x Initial program 95.1%
*-commutative95.1%
distribute-rgt-out--95.1%
cancel-sign-sub-inv95.1%
metadata-eval95.1%
neg-mul-195.1%
associate-+r+95.1%
unsub-neg95.1%
+-commutative95.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 79.5%
*-commutative79.5%
Simplified79.5%
Taylor expanded in x around inf 79.5%
*-commutative79.5%
Simplified79.5%
if -1.18e219 < x < -7.6000000000000004e-15 or 3.0999999999999998e-17 < x < 1.24999999999999994e157Initial program 97.3%
Taylor expanded in y around inf 64.8%
if -7.6000000000000004e-15 < x < 3.0999999999999998e-17Initial program 100.0%
Taylor expanded in x around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e-19) (not (<= x 4.7e-14))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e-19) || !(x <= 4.7e-14)) {
tmp = x * (y + 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 <= (-1.75d-19)) .or. (.not. (x <= 4.7d-14))) then
tmp = x * (y + z)
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-19) || !(x <= 4.7e-14)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.75e-19) or not (x <= 4.7e-14): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e-19) || !(x <= 4.7e-14)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.75e-19) || ~((x <= 4.7e-14))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e-19], N[Not[LessEqual[x, 4.7e-14]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-19} \lor \neg \left(x \leq 4.7 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.75000000000000008e-19 or 4.7000000000000002e-14 < x Initial program 96.3%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
Simplified99.4%
if -1.75000000000000008e-19 < x < 4.7000000000000002e-14Initial program 100.0%
Taylor expanded in x around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e-17) (not (<= x 0.0026))) (* x (+ y z)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-17) || !(x <= 0.0026)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - 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.1d-17)) .or. (.not. (x <= 0.0026d0))) then
tmp = x * (y + z)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-17) || !(x <= 0.0026)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e-17) or not (x <= 0.0026): tmp = x * (y + z) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e-17) || !(x <= 0.0026)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e-17) || ~((x <= 0.0026))) tmp = x * (y + z); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e-17], N[Not[LessEqual[x, 0.0026]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-17} \lor \neg \left(x \leq 0.0026\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -1.1e-17 or 0.0025999999999999999 < x Initial program 96.3%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
Simplified99.4%
if -1.1e-17 < x < 0.0025999999999999999Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 82.4%
*-commutative82.4%
Simplified82.4%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e-22) (not (<= x 5e-16))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e-22) || !(x <= 5e-16)) {
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 <= (-8.2d-22)) .or. (.not. (x <= 5d-16))) 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 <= -8.2e-22) || !(x <= 5e-16)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e-22) or not (x <= 5e-16): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e-22) || !(x <= 5e-16)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e-22) || ~((x <= 5e-16))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e-22], N[Not[LessEqual[x, 5e-16]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-22} \lor \neg \left(x \leq 5 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.1999999999999999e-22 or 5.0000000000000004e-16 < x Initial program 96.3%
Taylor expanded in y around inf 52.0%
if -8.1999999999999999e-22 < x < 5.0000000000000004e-16Initial program 100.0%
Taylor expanded in x around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
Final simplification66.3%
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.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 98.0%
Taylor expanded in x around 0 40.1%
mul-1-neg40.1%
Simplified40.1%
Final simplification40.1%
herbie shell --seed 2024027
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))