
(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 97.2%
*-commutative97.2%
distribute-rgt-out--97.2%
cancel-sign-sub-inv97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
distribute-lft-out100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.1e-26)
(* x y)
(if (<= x -6e-104)
(- z)
(if (<= x -6.9e-125)
(* x y)
(if (<= x 3.7e-84)
(- z)
(if (or (<= x 1.55e+41) (and (not (<= x 3.5e+97)) (<= x 7.2e+157)))
(* x y)
(* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e-26) {
tmp = x * y;
} else if (x <= -6e-104) {
tmp = -z;
} else if (x <= -6.9e-125) {
tmp = x * y;
} else if (x <= 3.7e-84) {
tmp = -z;
} else if ((x <= 1.55e+41) || (!(x <= 3.5e+97) && (x <= 7.2e+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 <= (-2.1d-26)) then
tmp = x * y
else if (x <= (-6d-104)) then
tmp = -z
else if (x <= (-6.9d-125)) then
tmp = x * y
else if (x <= 3.7d-84) then
tmp = -z
else if ((x <= 1.55d+41) .or. (.not. (x <= 3.5d+97)) .and. (x <= 7.2d+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 <= -2.1e-26) {
tmp = x * y;
} else if (x <= -6e-104) {
tmp = -z;
} else if (x <= -6.9e-125) {
tmp = x * y;
} else if (x <= 3.7e-84) {
tmp = -z;
} else if ((x <= 1.55e+41) || (!(x <= 3.5e+97) && (x <= 7.2e+157))) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.1e-26: tmp = x * y elif x <= -6e-104: tmp = -z elif x <= -6.9e-125: tmp = x * y elif x <= 3.7e-84: tmp = -z elif (x <= 1.55e+41) or (not (x <= 3.5e+97) and (x <= 7.2e+157)): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.1e-26) tmp = Float64(x * y); elseif (x <= -6e-104) tmp = Float64(-z); elseif (x <= -6.9e-125) tmp = Float64(x * y); elseif (x <= 3.7e-84) tmp = Float64(-z); elseif ((x <= 1.55e+41) || (!(x <= 3.5e+97) && (x <= 7.2e+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 <= -2.1e-26) tmp = x * y; elseif (x <= -6e-104) tmp = -z; elseif (x <= -6.9e-125) tmp = x * y; elseif (x <= 3.7e-84) tmp = -z; elseif ((x <= 1.55e+41) || (~((x <= 3.5e+97)) && (x <= 7.2e+157))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.1e-26], N[(x * y), $MachinePrecision], If[LessEqual[x, -6e-104], (-z), If[LessEqual[x, -6.9e-125], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.7e-84], (-z), If[Or[LessEqual[x, 1.55e+41], And[N[Not[LessEqual[x, 3.5e+97]], $MachinePrecision], LessEqual[x, 7.2e+157]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-26}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-104}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq -6.9 \cdot 10^{-125}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-84}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+41} \lor \neg \left(x \leq 3.5 \cdot 10^{+97}\right) \land x \leq 7.2 \cdot 10^{+157}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.10000000000000008e-26 or -6.0000000000000005e-104 < x < -6.89999999999999973e-125 or 3.6999999999999999e-84 < x < 1.55e41 or 3.5000000000000001e97 < x < 7.20000000000000049e157Initial program 99.1%
Taylor expanded in y around inf 68.0%
if -2.10000000000000008e-26 < x < -6.0000000000000005e-104 or -6.89999999999999973e-125 < x < 3.6999999999999999e-84Initial program 100.0%
Taylor expanded in x around 0 81.4%
mul-1-neg81.4%
Simplified81.4%
if 1.55e41 < x < 3.5000000000000001e97 or 7.20000000000000049e157 < x Initial program 85.3%
Taylor expanded in y around 0 69.3%
Taylor expanded in x around inf 69.3%
*-commutative69.3%
Simplified69.3%
Final simplification73.5%
(FPCore (x y z)
:precision binary64
(if (or (<= x -4.3e-26)
(not
(or (<= x -7.5e-104) (and (not (<= x -7.2e-125)) (<= x 8.5e-84)))))
(* x (+ y z))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e-26) || !((x <= -7.5e-104) || (!(x <= -7.2e-125) && (x <= 8.5e-84)))) {
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 <= (-4.3d-26)) .or. (.not. (x <= (-7.5d-104)) .or. (.not. (x <= (-7.2d-125))) .and. (x <= 8.5d-84))) 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 <= -4.3e-26) || !((x <= -7.5e-104) || (!(x <= -7.2e-125) && (x <= 8.5e-84)))) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.3e-26) or not ((x <= -7.5e-104) or (not (x <= -7.2e-125) and (x <= 8.5e-84))): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.3e-26) || !((x <= -7.5e-104) || (!(x <= -7.2e-125) && (x <= 8.5e-84)))) 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 <= -4.3e-26) || ~(((x <= -7.5e-104) || (~((x <= -7.2e-125)) && (x <= 8.5e-84))))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.3e-26], N[Not[Or[LessEqual[x, -7.5e-104], And[N[Not[LessEqual[x, -7.2e-125]], $MachinePrecision], LessEqual[x, 8.5e-84]]]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{-26} \lor \neg \left(x \leq -7.5 \cdot 10^{-104} \lor \neg \left(x \leq -7.2 \cdot 10^{-125}\right) \land x \leq 8.5 \cdot 10^{-84}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.29999999999999988e-26 or -7.5e-104 < x < -7.2000000000000004e-125 or 8.4999999999999994e-84 < x Initial program 95.5%
Taylor expanded in x around inf 94.2%
+-commutative94.2%
Simplified94.2%
if -4.29999999999999988e-26 < x < -7.5e-104 or -7.2000000000000004e-125 < x < 8.4999999999999994e-84Initial program 100.0%
Taylor expanded in x around 0 81.4%
mul-1-neg81.4%
Simplified81.4%
Final simplification89.1%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6e-26)
(and (not (<= x -2.3e-101))
(or (<= x -7.2e-125) (not (<= x 2.8e-83)))))
(* x (+ y z))
(* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-26) || (!(x <= -2.3e-101) && ((x <= -7.2e-125) || !(x <= 2.8e-83)))) {
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 <= (-6d-26)) .or. (.not. (x <= (-2.3d-101))) .and. (x <= (-7.2d-125)) .or. (.not. (x <= 2.8d-83))) 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 <= -6e-26) || (!(x <= -2.3e-101) && ((x <= -7.2e-125) || !(x <= 2.8e-83)))) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-26) or (not (x <= -2.3e-101) and ((x <= -7.2e-125) or not (x <= 2.8e-83))): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-26) || (!(x <= -2.3e-101) && ((x <= -7.2e-125) || !(x <= 2.8e-83)))) 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 <= -6e-26) || (~((x <= -2.3e-101)) && ((x <= -7.2e-125) || ~((x <= 2.8e-83))))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-26], And[N[Not[LessEqual[x, -2.3e-101]], $MachinePrecision], Or[LessEqual[x, -7.2e-125], N[Not[LessEqual[x, 2.8e-83]], $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 -6 \cdot 10^{-26} \lor \neg \left(x \leq -2.3 \cdot 10^{-101}\right) \land \left(x \leq -7.2 \cdot 10^{-125} \lor \neg \left(x \leq 2.8 \cdot 10^{-83}\right)\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -6.00000000000000023e-26 or -2.2999999999999999e-101 < x < -7.2000000000000004e-125 or 2.8000000000000001e-83 < x Initial program 95.5%
Taylor expanded in x around inf 94.2%
+-commutative94.2%
Simplified94.2%
if -6.00000000000000023e-26 < x < -2.2999999999999999e-101 or -7.2000000000000004e-125 < x < 2.8000000000000001e-83Initial program 100.0%
Taylor expanded in y around 0 81.4%
Final simplification89.1%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2.1e-25)
(and (not (<= x -6.2e-104))
(or (<= x -7.2e-125) (not (<= x 2.8e-83)))))
(* x y)
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-25) || (!(x <= -6.2e-104) && ((x <= -7.2e-125) || !(x <= 2.8e-83)))) {
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 <= (-2.1d-25)) .or. (.not. (x <= (-6.2d-104))) .and. (x <= (-7.2d-125)) .or. (.not. (x <= 2.8d-83))) 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 <= -2.1e-25) || (!(x <= -6.2e-104) && ((x <= -7.2e-125) || !(x <= 2.8e-83)))) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e-25) or (not (x <= -6.2e-104) and ((x <= -7.2e-125) or not (x <= 2.8e-83))): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e-25) || (!(x <= -6.2e-104) && ((x <= -7.2e-125) || !(x <= 2.8e-83)))) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.1e-25) || (~((x <= -6.2e-104)) && ((x <= -7.2e-125) || ~((x <= 2.8e-83))))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e-25], And[N[Not[LessEqual[x, -6.2e-104]], $MachinePrecision], Or[LessEqual[x, -7.2e-125], N[Not[LessEqual[x, 2.8e-83]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-25} \lor \neg \left(x \leq -6.2 \cdot 10^{-104}\right) \land \left(x \leq -7.2 \cdot 10^{-125} \lor \neg \left(x \leq 2.8 \cdot 10^{-83}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.10000000000000002e-25 or -6.19999999999999951e-104 < x < -7.2000000000000004e-125 or 2.8000000000000001e-83 < x Initial program 95.5%
Taylor expanded in y around inf 60.3%
if -2.10000000000000002e-25 < x < -6.19999999999999951e-104 or -7.2000000000000004e-125 < x < 2.8000000000000001e-83Initial program 100.0%
Taylor expanded in x around 0 81.4%
mul-1-neg81.4%
Simplified81.4%
Final simplification68.7%
(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%
distribute-rgt-out--97.2%
cancel-sign-sub-inv97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
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 97.2%
Taylor expanded in x around 0 36.7%
mul-1-neg36.7%
Simplified36.7%
Final simplification36.7%
herbie shell --seed 2024024
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))