
(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 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-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e+44) (* z x) (if (or (<= x -8.2e-82) (not (<= x 1.05e-24))) (* y x) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+44) {
tmp = z * x;
} else if ((x <= -8.2e-82) || !(x <= 1.05e-24)) {
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+44)) then
tmp = z * x
else if ((x <= (-8.2d-82)) .or. (.not. (x <= 1.05d-24))) 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+44) {
tmp = z * x;
} else if ((x <= -8.2e-82) || !(x <= 1.05e-24)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e+44: tmp = z * x elif (x <= -8.2e-82) or not (x <= 1.05e-24): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e+44) tmp = Float64(z * x); elseif ((x <= -8.2e-82) || !(x <= 1.05e-24)) 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+44) tmp = z * x; elseif ((x <= -8.2e-82) || ~((x <= 1.05e-24))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e+44], N[(z * x), $MachinePrecision], If[Or[LessEqual[x, -8.2e-82], N[Not[LessEqual[x, 1.05e-24]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+44}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{-82} \lor \neg \left(x \leq 1.05 \cdot 10^{-24}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.2e44Initial program 92.5%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 68.9%
if -7.2e44 < x < -8.19999999999999992e-82 or 1.05e-24 < x Initial program 98.9%
Taylor expanded in y around inf 65.4%
if -8.19999999999999992e-82 < x < 1.05e-24Initial program 100.0%
Taylor expanded in x around 0 77.8%
neg-mul-177.8%
Simplified77.8%
Final simplification71.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.45e-78) (not (<= x 5.5e-25))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-78) || !(x <= 5.5e-25)) {
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 <= (-1.45d-78)) .or. (.not. (x <= 5.5d-25))) 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 <= -1.45e-78) || !(x <= 5.5e-25)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.45e-78) or not (x <= 5.5e-25): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.45e-78) || !(x <= 5.5e-25)) 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 <= -1.45e-78) || ~((x <= 5.5e-25))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.45e-78], N[Not[LessEqual[x, 5.5e-25]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-78} \lor \neg \left(x \leq 5.5 \cdot 10^{-25}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.45e-78 or 5.50000000000000004e-25 < x Initial program 96.5%
Taylor expanded in x around inf 94.6%
+-commutative94.6%
Simplified94.6%
if -1.45e-78 < x < 5.50000000000000004e-25Initial program 100.0%
Taylor expanded in x around 0 77.8%
neg-mul-177.8%
Simplified77.8%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e-77) (not (<= x 40000000000000.0))) (* (+ y z) x) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-77) || !(x <= 40000000000000.0)) {
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 <= (-2.6d-77)) .or. (.not. (x <= 40000000000000.0d0))) 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 <= -2.6e-77) || !(x <= 40000000000000.0)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e-77) or not (x <= 40000000000000.0): tmp = (y + z) * x else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e-77) || !(x <= 40000000000000.0)) 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 <= -2.6e-77) || ~((x <= 40000000000000.0))) tmp = (y + z) * x; else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e-77], N[Not[LessEqual[x, 40000000000000.0]], $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 -2.6 \cdot 10^{-77} \lor \neg \left(x \leq 40000000000000\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -2.6000000000000001e-77 or 4e13 < x Initial program 96.2%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
Simplified98.7%
if -2.6000000000000001e-77 < x < 4e13Initial program 100.0%
Taylor expanded in y around 0 76.8%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-92) (not (<= x 6.8e-25))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-92) || !(x <= 6.8e-25)) {
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 <= (-4.5d-92)) .or. (.not. (x <= 6.8d-25))) 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 <= -4.5e-92) || !(x <= 6.8e-25)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-92) or not (x <= 6.8e-25): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-92) || !(x <= 6.8e-25)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e-92) || ~((x <= 6.8e-25))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-92], N[Not[LessEqual[x, 6.8e-25]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-92} \lor \neg \left(x \leq 6.8 \cdot 10^{-25}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.5e-92 or 6.80000000000000003e-25 < x Initial program 96.5%
Taylor expanded in y around inf 56.7%
if -4.5e-92 < x < 6.80000000000000003e-25Initial program 100.0%
Taylor expanded in x around 0 77.8%
neg-mul-177.8%
Simplified77.8%
Final simplification65.9%
(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%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.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 37.1%
neg-mul-137.1%
Simplified37.1%
Final simplification37.1%
herbie shell --seed 2024010
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))