
(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 6 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 (- (* 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%
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
(if (<= x -6.7e+212)
(* x z)
(if (<= x -3.2e+167)
(* x y)
(if (<= x -8.8e+61)
(* x z)
(if (or (<= x -2.7e-75) (not (<= x 5.5e-20))) (* x y) (- z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.7e+212) {
tmp = x * z;
} else if (x <= -3.2e+167) {
tmp = x * y;
} else if (x <= -8.8e+61) {
tmp = x * z;
} else if ((x <= -2.7e-75) || !(x <= 5.5e-20)) {
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 <= (-6.7d+212)) then
tmp = x * z
else if (x <= (-3.2d+167)) then
tmp = x * y
else if (x <= (-8.8d+61)) then
tmp = x * z
else if ((x <= (-2.7d-75)) .or. (.not. (x <= 5.5d-20))) 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 <= -6.7e+212) {
tmp = x * z;
} else if (x <= -3.2e+167) {
tmp = x * y;
} else if (x <= -8.8e+61) {
tmp = x * z;
} else if ((x <= -2.7e-75) || !(x <= 5.5e-20)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.7e+212: tmp = x * z elif x <= -3.2e+167: tmp = x * y elif x <= -8.8e+61: tmp = x * z elif (x <= -2.7e-75) or not (x <= 5.5e-20): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.7e+212) tmp = Float64(x * z); elseif (x <= -3.2e+167) tmp = Float64(x * y); elseif (x <= -8.8e+61) tmp = Float64(x * z); elseif ((x <= -2.7e-75) || !(x <= 5.5e-20)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.7e+212) tmp = x * z; elseif (x <= -3.2e+167) tmp = x * y; elseif (x <= -8.8e+61) tmp = x * z; elseif ((x <= -2.7e-75) || ~((x <= 5.5e-20))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.7e+212], N[(x * z), $MachinePrecision], If[LessEqual[x, -3.2e+167], N[(x * y), $MachinePrecision], If[LessEqual[x, -8.8e+61], N[(x * z), $MachinePrecision], If[Or[LessEqual[x, -2.7e-75], N[Not[LessEqual[x, 5.5e-20]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.7 \cdot 10^{+212}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{+167}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -8.8 \cdot 10^{+61}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-75} \lor \neg \left(x \leq 5.5 \cdot 10^{-20}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.6999999999999997e212 or -3.19999999999999981e167 < x < -8.8000000000000001e61Initial program 92.7%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 71.4%
if -6.6999999999999997e212 < x < -3.19999999999999981e167 or -8.8000000000000001e61 < x < -2.6999999999999998e-75 or 5.4999999999999996e-20 < x Initial program 98.0%
Taylor expanded in y around inf 61.3%
if -2.6999999999999998e-75 < x < 5.4999999999999996e-20Initial program 100.0%
Taylor expanded in x around 0 74.4%
neg-mul-174.4%
Simplified74.4%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.15e-75) (not (<= x 1.25e-19))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.15e-75) || !(x <= 1.25e-19)) {
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 <= (-3.15d-75)) .or. (.not. (x <= 1.25d-19))) 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 <= -3.15e-75) || !(x <= 1.25e-19)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.15e-75) or not (x <= 1.25e-19): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.15e-75) || !(x <= 1.25e-19)) 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 <= -3.15e-75) || ~((x <= 1.25e-19))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.15e-75], N[Not[LessEqual[x, 1.25e-19]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.15 \cdot 10^{-75} \lor \neg \left(x \leq 1.25 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.14999999999999992e-75 or 1.2500000000000001e-19 < x Initial program 96.4%
Taylor expanded in x around inf 94.0%
+-commutative94.0%
Simplified94.0%
if -3.14999999999999992e-75 < x < 1.2500000000000001e-19Initial program 100.0%
Taylor expanded in x around 0 74.4%
neg-mul-174.4%
Simplified74.4%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-75) (not (<= x 6.5e-20))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-75) || !(x <= 6.5e-20)) {
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 <= (-2d-75)) .or. (.not. (x <= 6.5d-20))) 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 <= -2e-75) || !(x <= 6.5e-20)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-75) or not (x <= 6.5e-20): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-75) || !(x <= 6.5e-20)) 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 <= -2e-75) || ~((x <= 6.5e-20))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-75], N[Not[LessEqual[x, 6.5e-20]], $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 -2 \cdot 10^{-75} \lor \neg \left(x \leq 6.5 \cdot 10^{-20}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -1.9999999999999999e-75 or 6.50000000000000032e-20 < x Initial program 96.4%
Taylor expanded in x around inf 94.0%
+-commutative94.0%
Simplified94.0%
if -1.9999999999999999e-75 < x < 6.50000000000000032e-20Initial program 100.0%
Taylor expanded in y around 0 74.4%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e-76) (not (<= x 7.5e-20))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-76) || !(x <= 7.5e-20)) {
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 <= (-5.5d-76)) .or. (.not. (x <= 7.5d-20))) 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 <= -5.5e-76) || !(x <= 7.5e-20)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-76) or not (x <= 7.5e-20): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-76) || !(x <= 7.5e-20)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.5e-76) || ~((x <= 7.5e-20))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-76], N[Not[LessEqual[x, 7.5e-20]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-76} \lor \neg \left(x \leq 7.5 \cdot 10^{-20}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.50000000000000014e-76 or 7.49999999999999981e-20 < x Initial program 96.4%
Taylor expanded in y around inf 54.5%
if -5.50000000000000014e-76 < x < 7.49999999999999981e-20Initial program 100.0%
Taylor expanded in x around 0 74.4%
neg-mul-174.4%
Simplified74.4%
Final simplification63.5%
(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 37.1%
neg-mul-137.1%
Simplified37.1%
Final simplification37.1%
herbie shell --seed 2024046
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))