
(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 (+ y z) x (- z)))
double code(double x, double y, double z) {
return fma((y + z), x, -z);
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, -z\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
metadata-eval98.0%
distribute-rgt-in98.0%
neg-mul-198.0%
associate-+l+98.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.25e+233)
(* y x)
(if (<= x -15500000000000.0)
(* z x)
(if (<= x 5.08e-85)
(- z)
(if (or (<= x 7e+109) (not (<= x 6.2e+196))) (* y x) (* z x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e+233) {
tmp = y * x;
} else if (x <= -15500000000000.0) {
tmp = z * x;
} else if (x <= 5.08e-85) {
tmp = -z;
} else if ((x <= 7e+109) || !(x <= 6.2e+196)) {
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.25d+233)) then
tmp = y * x
else if (x <= (-15500000000000.0d0)) then
tmp = z * x
else if (x <= 5.08d-85) then
tmp = -z
else if ((x <= 7d+109) .or. (.not. (x <= 6.2d+196))) 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.25e+233) {
tmp = y * x;
} else if (x <= -15500000000000.0) {
tmp = z * x;
} else if (x <= 5.08e-85) {
tmp = -z;
} else if ((x <= 7e+109) || !(x <= 6.2e+196)) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.25e+233: tmp = y * x elif x <= -15500000000000.0: tmp = z * x elif x <= 5.08e-85: tmp = -z elif (x <= 7e+109) or not (x <= 6.2e+196): tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.25e+233) tmp = Float64(y * x); elseif (x <= -15500000000000.0) tmp = Float64(z * x); elseif (x <= 5.08e-85) tmp = Float64(-z); elseif ((x <= 7e+109) || !(x <= 6.2e+196)) 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.25e+233) tmp = y * x; elseif (x <= -15500000000000.0) tmp = z * x; elseif (x <= 5.08e-85) tmp = -z; elseif ((x <= 7e+109) || ~((x <= 6.2e+196))) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.25e+233], N[(y * x), $MachinePrecision], If[LessEqual[x, -15500000000000.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 5.08e-85], (-z), If[Or[LessEqual[x, 7e+109], N[Not[LessEqual[x, 6.2e+196]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+233}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -15500000000000:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 5.08 \cdot 10^{-85}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+109} \lor \neg \left(x \leq 6.2 \cdot 10^{+196}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -1.25000000000000002e233 or 5.0799999999999997e-85 < x < 6.99999999999999966e109 or 6.2000000000000002e196 < x Initial program 95.3%
Taylor expanded in y around inf 65.2%
if -1.25000000000000002e233 < x < -1.55e13 or 6.99999999999999966e109 < x < 6.2000000000000002e196Initial program 98.4%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 69.7%
if -1.55e13 < x < 5.0799999999999997e-85Initial program 99.9%
Taylor expanded in x around 0 75.7%
neg-mul-175.7%
Simplified75.7%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-5) (not (<= x 5.08e-85))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-5) || !(x <= 5.08e-85)) {
tmp = (y + 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 <= (-3d-5)) .or. (.not. (x <= 5.08d-85))) then
tmp = (y + 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 <= -3e-5) || !(x <= 5.08e-85)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-5) or not (x <= 5.08e-85): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-5) || !(x <= 5.08e-85)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3e-5) || ~((x <= 5.08e-85))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-5], N[Not[LessEqual[x, 5.08e-85]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-5} \lor \neg \left(x \leq 5.08 \cdot 10^{-85}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.00000000000000008e-5 or 5.0799999999999997e-85 < x Initial program 96.7%
Taylor expanded in x around inf 92.5%
+-commutative92.5%
Simplified92.5%
if -3.00000000000000008e-5 < x < 5.0799999999999997e-85Initial program 99.9%
Taylor expanded in x around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.45) (not (<= x 1.45e-5))) (* (+ y z) x) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.45) || !(x <= 1.45e-5)) {
tmp = (y + z) * x;
} 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.45d0)) .or. (.not. (x <= 1.45d-5))) then
tmp = (y + z) * x
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.45) || !(x <= 1.45e-5)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.45) or not (x <= 1.45e-5): tmp = (y + z) * x else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.45) || !(x <= 1.45e-5)) tmp = Float64(Float64(y + z) * x); 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.45) || ~((x <= 1.45e-5))) tmp = (y + z) * x; else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.45], N[Not[LessEqual[x, 1.45e-5]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.45 \lor \neg \left(x \leq 1.45 \cdot 10^{-5}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -0.450000000000000011 or 1.45e-5 < x Initial program 96.2%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
Simplified99.4%
if -0.450000000000000011 < x < 1.45e-5Initial program 99.9%
Taylor expanded in y around 0 72.8%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.0) (not (<= x 4.8e-5))) (* (+ y z) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.0) || !(x <= 4.8e-5)) {
tmp = (y + z) * x;
} else {
tmp = (z * 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 <= (-4.0d0)) .or. (.not. (x <= 4.8d-5))) then
tmp = (y + z) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.0) || !(x <= 4.8e-5)) {
tmp = (y + z) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.0) or not (x <= 4.8e-5): tmp = (y + z) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.0) || !(x <= 4.8e-5)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.0) || ~((x <= 4.8e-5))) tmp = (y + z) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.0], N[Not[LessEqual[x, 4.8e-5]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \lor \neg \left(x \leq 4.8 \cdot 10^{-5}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
if x < -4 or 4.8000000000000001e-5 < x Initial program 96.2%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
Simplified99.4%
if -4 < x < 4.8000000000000001e-5Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 72.8%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-5) (not (<= x 5.08e-85))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-5) || !(x <= 5.08e-85)) {
tmp = y * 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 <= (-3d-5)) .or. (.not. (x <= 5.08d-85))) then
tmp = y * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-5) || !(x <= 5.08e-85)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-5) or not (x <= 5.08e-85): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-5) || !(x <= 5.08e-85)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3e-5) || ~((x <= 5.08e-85))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-5], N[Not[LessEqual[x, 5.08e-85]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-5} \lor \neg \left(x \leq 5.08 \cdot 10^{-85}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.00000000000000008e-5 or 5.0799999999999997e-85 < x Initial program 96.7%
Taylor expanded in y around inf 52.0%
if -3.00000000000000008e-5 < x < 5.0799999999999997e-85Initial program 99.9%
Taylor expanded in x around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification62.1%
(FPCore (x y z) :precision binary64 (- (* (+ y z) x) z))
double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y + z) * x) - z
end function
public static double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
def code(x, y, z): return ((y + z) * x) - z
function code(x, y, z) return Float64(Float64(Float64(y + z) * x) - z) end
function tmp = code(x, y, z) tmp = ((y + z) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + z\right) \cdot x - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.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 36.2%
neg-mul-136.2%
Simplified36.2%
Final simplification36.2%
herbie shell --seed 2024034
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))