
(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 8 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 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
distribute-lft-out99.9%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1e+73)
(* x z)
(if (<= x -0.0066)
(* x y)
(if (<= x 1.14e-138)
(- z)
(if (<= x 2.1e+63)
(* x y)
(if (or (<= x 8.6e+97)
(and (not (<= x 1.16e+113))
(or (<= x 1.7e+170)
(and (not (<= x 4.2e+235)) (<= x 2.5e+258)))))
(* x z)
(* x y)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e+73) {
tmp = x * z;
} else if (x <= -0.0066) {
tmp = x * y;
} else if (x <= 1.14e-138) {
tmp = -z;
} else if (x <= 2.1e+63) {
tmp = x * y;
} else if ((x <= 8.6e+97) || (!(x <= 1.16e+113) && ((x <= 1.7e+170) || (!(x <= 4.2e+235) && (x <= 2.5e+258))))) {
tmp = x * z;
} else {
tmp = x * y;
}
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 <= (-1d+73)) then
tmp = x * z
else if (x <= (-0.0066d0)) then
tmp = x * y
else if (x <= 1.14d-138) then
tmp = -z
else if (x <= 2.1d+63) then
tmp = x * y
else if ((x <= 8.6d+97) .or. (.not. (x <= 1.16d+113)) .and. (x <= 1.7d+170) .or. (.not. (x <= 4.2d+235)) .and. (x <= 2.5d+258)) then
tmp = x * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1e+73) {
tmp = x * z;
} else if (x <= -0.0066) {
tmp = x * y;
} else if (x <= 1.14e-138) {
tmp = -z;
} else if (x <= 2.1e+63) {
tmp = x * y;
} else if ((x <= 8.6e+97) || (!(x <= 1.16e+113) && ((x <= 1.7e+170) || (!(x <= 4.2e+235) && (x <= 2.5e+258))))) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e+73: tmp = x * z elif x <= -0.0066: tmp = x * y elif x <= 1.14e-138: tmp = -z elif x <= 2.1e+63: tmp = x * y elif (x <= 8.6e+97) or (not (x <= 1.16e+113) and ((x <= 1.7e+170) or (not (x <= 4.2e+235) and (x <= 2.5e+258)))): tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e+73) tmp = Float64(x * z); elseif (x <= -0.0066) tmp = Float64(x * y); elseif (x <= 1.14e-138) tmp = Float64(-z); elseif (x <= 2.1e+63) tmp = Float64(x * y); elseif ((x <= 8.6e+97) || (!(x <= 1.16e+113) && ((x <= 1.7e+170) || (!(x <= 4.2e+235) && (x <= 2.5e+258))))) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1e+73) tmp = x * z; elseif (x <= -0.0066) tmp = x * y; elseif (x <= 1.14e-138) tmp = -z; elseif (x <= 2.1e+63) tmp = x * y; elseif ((x <= 8.6e+97) || (~((x <= 1.16e+113)) && ((x <= 1.7e+170) || (~((x <= 4.2e+235)) && (x <= 2.5e+258))))) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e+73], N[(x * z), $MachinePrecision], If[LessEqual[x, -0.0066], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.14e-138], (-z), If[LessEqual[x, 2.1e+63], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 8.6e+97], And[N[Not[LessEqual[x, 1.16e+113]], $MachinePrecision], Or[LessEqual[x, 1.7e+170], And[N[Not[LessEqual[x, 4.2e+235]], $MachinePrecision], LessEqual[x, 2.5e+258]]]]], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+73}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -0.0066:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.14 \cdot 10^{-138}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+63}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{+97} \lor \neg \left(x \leq 1.16 \cdot 10^{+113}\right) \land \left(x \leq 1.7 \cdot 10^{+170} \lor \neg \left(x \leq 4.2 \cdot 10^{+235}\right) \land x \leq 2.5 \cdot 10^{+258}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -9.99999999999999983e72 or 2.1000000000000002e63 < x < 8.5999999999999996e97 or 1.1600000000000001e113 < x < 1.7000000000000001e170 or 4.2000000000000001e235 < x < 2.5e258Initial program 96.3%
Taylor expanded in y around 0 71.8%
sub-neg71.8%
metadata-eval71.8%
distribute-rgt-in71.8%
mul-1-neg71.8%
sub-neg71.8%
*-commutative71.8%
Simplified71.8%
Taylor expanded in x around inf 71.8%
*-commutative71.8%
Simplified71.8%
if -9.99999999999999983e72 < x < -0.0066 or 1.1399999999999999e-138 < x < 2.1000000000000002e63 or 8.5999999999999996e97 < x < 1.1600000000000001e113 or 1.7000000000000001e170 < x < 4.2000000000000001e235 or 2.5e258 < x Initial program 95.4%
Taylor expanded in y around inf 69.0%
if -0.0066 < x < 1.1399999999999999e-138Initial program 99.9%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification72.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0066) (not (<= x 5.1e-138))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0066) || !(x <= 5.1e-138)) {
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 <= (-0.0066d0)) .or. (.not. (x <= 5.1d-138))) 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 <= -0.0066) || !(x <= 5.1e-138)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0066) or not (x <= 5.1e-138): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0066) || !(x <= 5.1e-138)) 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 <= -0.0066) || ~((x <= 5.1e-138))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0066], N[Not[LessEqual[x, 5.1e-138]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0066 \lor \neg \left(x \leq 5.1 \cdot 10^{-138}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.0066 or 5.1000000000000002e-138 < x Initial program 95.8%
Taylor expanded in x around inf 93.2%
+-commutative93.2%
Simplified93.2%
if -0.0066 < x < 5.1000000000000002e-138Initial program 99.9%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0074) (not (<= x 5.1e-138))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0074) || !(x <= 5.1e-138)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
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 <= (-0.0074d0)) .or. (.not. (x <= 5.1d-138))) then
tmp = x * (y + z)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0074) || !(x <= 5.1e-138)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0074) or not (x <= 5.1e-138): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0074) || !(x <= 5.1e-138)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0074) || ~((x <= 5.1e-138))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0074], N[Not[LessEqual[x, 5.1e-138]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0074 \lor \neg \left(x \leq 5.1 \cdot 10^{-138}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -0.0074000000000000003 or 5.1000000000000002e-138 < x Initial program 95.8%
Taylor expanded in x around inf 93.2%
+-commutative93.2%
Simplified93.2%
if -0.0074000000000000003 < x < 5.1000000000000002e-138Initial program 99.9%
Taylor expanded in y around 0 79.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -14.0) (not (<= x 1.0))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -14.0) || !(x <= 1.0)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - 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 <= (-14.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (y + z)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -14.0) || !(x <= 1.0)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -14.0) or not (x <= 1.0): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -14.0) || !(x <= 1.0)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -14.0) || ~((x <= 1.0))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -14.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -14 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -14 or 1 < x Initial program 95.0%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -14 < x < 1Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
distribute-rgt-in99.9%
metadata-eval99.9%
neg-mul-199.9%
associate-+r+99.9%
unsub-neg99.9%
+-commutative99.9%
distribute-lft-out99.9%
Simplified99.9%
+-commutative99.9%
flip-+56.5%
associate-*r/55.6%
difference-of-squares55.8%
sub-neg55.8%
add-sqr-sqrt23.3%
sqrt-unprod55.6%
sqr-neg55.6%
sqrt-unprod32.2%
add-sqr-sqrt55.1%
pow255.1%
sub-neg55.1%
add-sqr-sqrt22.9%
sqrt-unprod54.5%
sqr-neg54.5%
sqrt-unprod32.5%
add-sqr-sqrt55.8%
Applied egg-rr55.8%
associate-/l*56.6%
unpow256.6%
associate-/r*99.8%
*-inverses99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in z around 0 98.2%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= x -0.0066) (* x y) (if (<= x 5.1e-138) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.0066) {
tmp = x * y;
} else if (x <= 5.1e-138) {
tmp = -z;
} else {
tmp = x * y;
}
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 <= (-0.0066d0)) then
tmp = x * y
else if (x <= 5.1d-138) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.0066) {
tmp = x * y;
} else if (x <= 5.1e-138) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.0066: tmp = x * y elif x <= 5.1e-138: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.0066) tmp = Float64(x * y); elseif (x <= 5.1e-138) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.0066) tmp = x * y; elseif (x <= 5.1e-138) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.0066], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.1e-138], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0066:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.1 \cdot 10^{-138}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -0.0066 or 5.1000000000000002e-138 < x Initial program 95.8%
Taylor expanded in y around inf 54.4%
if -0.0066 < x < 5.1000000000000002e-138Initial program 99.9%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification62.4%
(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 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
distribute-lft-out99.9%
Simplified99.9%
Final simplification99.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 32.4%
mul-1-neg32.4%
Simplified32.4%
Final simplification32.4%
herbie shell --seed 2023297
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))