
(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 (+ 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 96.9%
*-commutative96.9%
sub-neg96.9%
distribute-rgt-in96.9%
metadata-eval96.9%
neg-mul-196.9%
associate-+r+96.9%
unsub-neg96.9%
+-commutative96.9%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= x -8.2e+126) (* z x) (if (or (<= x -9.8e-8) (not (<= x 1e-29))) (* y x) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.2e+126) {
tmp = z * x;
} else if ((x <= -9.8e-8) || !(x <= 1e-29)) {
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 <= (-8.2d+126)) then
tmp = z * x
else if ((x <= (-9.8d-8)) .or. (.not. (x <= 1d-29))) 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 <= -8.2e+126) {
tmp = z * x;
} else if ((x <= -9.8e-8) || !(x <= 1e-29)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.2e+126: tmp = z * x elif (x <= -9.8e-8) or not (x <= 1e-29): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.2e+126) tmp = Float64(z * x); elseif ((x <= -9.8e-8) || !(x <= 1e-29)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.2e+126) tmp = z * x; elseif ((x <= -9.8e-8) || ~((x <= 1e-29))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.2e+126], N[(z * x), $MachinePrecision], If[Or[LessEqual[x, -9.8e-8], N[Not[LessEqual[x, 1e-29]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+126}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -9.8 \cdot 10^{-8} \lor \neg \left(x \leq 10^{-29}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.2000000000000001e126Initial program 94.7%
*-commutative94.7%
sub-neg94.7%
distribute-rgt-in94.7%
metadata-eval94.7%
neg-mul-194.7%
associate-+r+94.7%
unsub-neg94.7%
+-commutative94.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 68.6%
Taylor expanded in x around inf 68.6%
if -8.2000000000000001e126 < x < -9.8000000000000004e-8 or 9.99999999999999943e-30 < x Initial program 94.3%
Taylor expanded in y around inf 55.7%
if -9.8000000000000004e-8 < x < 9.99999999999999943e-30Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 73.1%
mul-1-neg73.1%
Simplified73.1%
Final simplification65.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* (+ y z) x) (- (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (y + z) * x;
} else {
tmp = (y * 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.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (y + z) * x
else
tmp = (y * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (y + z) * x;
} else {
tmp = (y * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = (y + z) * x else: tmp = (y * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(y * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = (y + z) * x; else tmp = (y * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x - z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 94.2%
Taylor expanded in x around inf 98.2%
+-commutative98.2%
Simplified98.2%
if -1 < x < 1Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.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 0 98.6%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.8e-7) (not (<= x 5.3e-30))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-7) || !(x <= 5.3e-30)) {
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 <= (-8.8d-7)) .or. (.not. (x <= 5.3d-30))) 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 <= -8.8e-7) || !(x <= 5.3e-30)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.8e-7) or not (x <= 5.3e-30): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.8e-7) || !(x <= 5.3e-30)) 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 <= -8.8e-7) || ~((x <= 5.3e-30))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.8e-7], N[Not[LessEqual[x, 5.3e-30]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-7} \lor \neg \left(x \leq 5.3 \cdot 10^{-30}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.8000000000000004e-7 or 5.29999999999999974e-30 < x Initial program 94.4%
Taylor expanded in x around inf 96.9%
+-commutative96.9%
Simplified96.9%
if -8.8000000000000004e-7 < x < 5.29999999999999974e-30Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 73.1%
mul-1-neg73.1%
Simplified73.1%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e-7) (not (<= x 9.8e-30))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-7) || !(x <= 9.8e-30)) {
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 <= (-7.2d-7)) .or. (.not. (x <= 9.8d-30))) 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 <= -7.2e-7) || !(x <= 9.8e-30)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e-7) or not (x <= 9.8e-30): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e-7) || !(x <= 9.8e-30)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e-7) || ~((x <= 9.8e-30))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-7], N[Not[LessEqual[x, 9.8e-30]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-7} \lor \neg \left(x \leq 9.8 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.19999999999999989e-7 or 9.79999999999999942e-30 < x Initial program 94.4%
Taylor expanded in y around inf 51.1%
if -7.19999999999999989e-7 < x < 9.79999999999999942e-30Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 73.1%
mul-1-neg73.1%
Simplified73.1%
Final simplification60.7%
(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 96.9%
*-commutative96.9%
sub-neg96.9%
distribute-rgt-in96.9%
metadata-eval96.9%
neg-mul-196.9%
associate-+r+96.9%
unsub-neg96.9%
+-commutative96.9%
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 96.9%
*-commutative96.9%
sub-neg96.9%
distribute-rgt-in96.9%
metadata-eval96.9%
neg-mul-196.9%
associate-+r+96.9%
unsub-neg96.9%
+-commutative96.9%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 34.1%
mul-1-neg34.1%
Simplified34.1%
herbie shell --seed 2024137
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))