
(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 (- (* 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.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -2.4e+146) (* x z) (if (or (<= x -1.3e-55) (not (<= x 3.5e-66))) (* x y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+146) {
tmp = x * z;
} else if ((x <= -1.3e-55) || !(x <= 3.5e-66)) {
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.4d+146)) then
tmp = x * z
else if ((x <= (-1.3d-55)) .or. (.not. (x <= 3.5d-66))) 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.4e+146) {
tmp = x * z;
} else if ((x <= -1.3e-55) || !(x <= 3.5e-66)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e+146: tmp = x * z elif (x <= -1.3e-55) or not (x <= 3.5e-66): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e+146) tmp = Float64(x * z); elseif ((x <= -1.3e-55) || !(x <= 3.5e-66)) 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.4e+146) tmp = x * z; elseif ((x <= -1.3e-55) || ~((x <= 3.5e-66))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e+146], N[(x * z), $MachinePrecision], If[Or[LessEqual[x, -1.3e-55], N[Not[LessEqual[x, 3.5e-66]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+146}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{-55} \lor \neg \left(x \leq 3.5 \cdot 10^{-66}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.4000000000000002e146Initial program 87.9%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 68.5%
*-commutative68.5%
Simplified68.5%
if -2.4000000000000002e146 < x < -1.2999999999999999e-55 or 3.5e-66 < x Initial program 98.3%
Taylor expanded in y around inf 59.1%
if -1.2999999999999999e-55 < x < 3.5e-66Initial 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 84.1%
neg-mul-184.1%
Simplified84.1%
Final simplification70.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1e-14))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1e-14)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - 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 <= 1d-14))) then
tmp = x * (y + z)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1e-14)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1e-14): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1e-14)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1e-14))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1e-14]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 9.99999999999999999e-15 < x Initial program 95.2%
Taylor expanded in x around inf 98.2%
+-commutative98.2%
Simplified98.2%
if -1 < x < 9.99999999999999999e-15Initial 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 98.7%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-53) (not (<= x 3.6e-65))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-53) || !(x <= 3.6e-65)) {
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 <= (-4.5d-53)) .or. (.not. (x <= 3.6d-65))) 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 <= -4.5e-53) || !(x <= 3.6e-65)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-53) or not (x <= 3.6e-65): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-53) || !(x <= 3.6e-65)) 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 <= -4.5e-53) || ~((x <= 3.6e-65))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-53], N[Not[LessEqual[x, 3.6e-65]], $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 -4.5 \cdot 10^{-53} \lor \neg \left(x \leq 3.6 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -4.49999999999999985e-53 or 3.5999999999999998e-65 < x Initial program 96.1%
Taylor expanded in x around inf 92.4%
+-commutative92.4%
Simplified92.4%
if -4.49999999999999985e-53 < x < 3.5999999999999998e-65Initial 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 84.1%
Taylor expanded in z around 0 84.1%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.4e-50) (not (<= x 4.5e-64))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.4e-50) || !(x <= 4.5e-64)) {
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 <= (-7.4d-50)) .or. (.not. (x <= 4.5d-64))) 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 <= -7.4e-50) || !(x <= 4.5e-64)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.4e-50) or not (x <= 4.5e-64): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.4e-50) || !(x <= 4.5e-64)) 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 <= -7.4e-50) || ~((x <= 4.5e-64))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.4e-50], N[Not[LessEqual[x, 4.5e-64]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.4 \cdot 10^{-50} \lor \neg \left(x \leq 4.5 \cdot 10^{-64}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.4000000000000002e-50 or 4.5000000000000001e-64 < x Initial program 96.1%
Taylor expanded in x around inf 92.4%
+-commutative92.4%
Simplified92.4%
if -7.4000000000000002e-50 < x < 4.5000000000000001e-64Initial 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 84.1%
neg-mul-184.1%
Simplified84.1%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.6e-51) (not (<= x 2.3e-65))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-51) || !(x <= 2.3e-65)) {
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 <= (-8.6d-51)) .or. (.not. (x <= 2.3d-65))) 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 <= -8.6e-51) || !(x <= 2.3e-65)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6e-51) or not (x <= 2.3e-65): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6e-51) || !(x <= 2.3e-65)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.6e-51) || ~((x <= 2.3e-65))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6e-51], N[Not[LessEqual[x, 2.3e-65]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-51} \lor \neg \left(x \leq 2.3 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.5999999999999995e-51 or 2.3e-65 < x Initial program 96.1%
Taylor expanded in y around inf 56.0%
if -8.5999999999999995e-51 < x < 2.3e-65Initial 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 84.1%
neg-mul-184.1%
Simplified84.1%
Final simplification67.3%
(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.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 77.0%
Taylor expanded in x around 0 38.9%
neg-mul-138.9%
Simplified38.9%
(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 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.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 77.0%
Taylor expanded in x around 0 38.9%
neg-mul-138.9%
Simplified38.9%
neg-sub038.9%
sub-neg38.9%
add-sqr-sqrt14.5%
sqrt-unprod15.5%
sqr-neg15.5%
sqrt-unprod1.4%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
+-lft-identity2.5%
Simplified2.5%
herbie shell --seed 2024180
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))