
(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 (- (* 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 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%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3e+279)
(* x y)
(if (<= x -3.05e+65)
(* x z)
(if (<= x -8e-64)
(* x y)
(if (<= x 5e-33)
(- z)
(if (or (<= x 2.1e+30) (not (<= x 5.5e+228))) (* x y) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3e+279) {
tmp = x * y;
} else if (x <= -3.05e+65) {
tmp = x * z;
} else if (x <= -8e-64) {
tmp = x * y;
} else if (x <= 5e-33) {
tmp = -z;
} else if ((x <= 2.1e+30) || !(x <= 5.5e+228)) {
tmp = x * y;
} else {
tmp = 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 <= (-3d+279)) then
tmp = x * y
else if (x <= (-3.05d+65)) then
tmp = x * z
else if (x <= (-8d-64)) then
tmp = x * y
else if (x <= 5d-33) then
tmp = -z
else if ((x <= 2.1d+30) .or. (.not. (x <= 5.5d+228))) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3e+279) {
tmp = x * y;
} else if (x <= -3.05e+65) {
tmp = x * z;
} else if (x <= -8e-64) {
tmp = x * y;
} else if (x <= 5e-33) {
tmp = -z;
} else if ((x <= 2.1e+30) || !(x <= 5.5e+228)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3e+279: tmp = x * y elif x <= -3.05e+65: tmp = x * z elif x <= -8e-64: tmp = x * y elif x <= 5e-33: tmp = -z elif (x <= 2.1e+30) or not (x <= 5.5e+228): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3e+279) tmp = Float64(x * y); elseif (x <= -3.05e+65) tmp = Float64(x * z); elseif (x <= -8e-64) tmp = Float64(x * y); elseif (x <= 5e-33) tmp = Float64(-z); elseif ((x <= 2.1e+30) || !(x <= 5.5e+228)) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3e+279) tmp = x * y; elseif (x <= -3.05e+65) tmp = x * z; elseif (x <= -8e-64) tmp = x * y; elseif (x <= 5e-33) tmp = -z; elseif ((x <= 2.1e+30) || ~((x <= 5.5e+228))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3e+279], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.05e+65], N[(x * z), $MachinePrecision], If[LessEqual[x, -8e-64], N[(x * y), $MachinePrecision], If[LessEqual[x, 5e-33], (-z), If[Or[LessEqual[x, 2.1e+30], N[Not[LessEqual[x, 5.5e+228]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+279}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -3.05 \cdot 10^{+65}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-64}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-33}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+30} \lor \neg \left(x \leq 5.5 \cdot 10^{+228}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.9999999999999998e279 or -3.04999999999999982e65 < x < -7.99999999999999972e-64 or 5.00000000000000028e-33 < x < 2.1e30 or 5.50000000000000009e228 < x Initial program 94.3%
*-commutative94.3%
sub-neg94.3%
distribute-rgt-in94.3%
metadata-eval94.3%
neg-mul-194.3%
associate-+r+94.3%
unsub-neg94.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 89.3%
Taylor expanded in y around inf 73.6%
if -2.9999999999999998e279 < x < -3.04999999999999982e65 or 2.1e30 < x < 5.50000000000000009e228Initial program 95.0%
*-commutative95.0%
sub-neg95.0%
distribute-rgt-in95.0%
metadata-eval95.0%
neg-mul-195.0%
associate-+r+95.0%
unsub-neg95.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around 0 63.3%
if -7.99999999999999972e-64 < x < 5.00000000000000028e-33Initial 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 x around 0 70.0%
neg-mul-170.0%
Simplified70.0%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -3700000.0) (not (<= x 5.2e-19))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3700000.0) || !(x <= 5.2e-19)) {
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 <= (-3700000.0d0)) .or. (.not. (x <= 5.2d-19))) 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 <= -3700000.0) || !(x <= 5.2e-19)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3700000.0) or not (x <= 5.2e-19): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3700000.0) || !(x <= 5.2e-19)) 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 <= -3700000.0) || ~((x <= 5.2e-19))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3700000.0], N[Not[LessEqual[x, 5.2e-19]], $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 -3700000 \lor \neg \left(x \leq 5.2 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -3.7e6 or 5.20000000000000026e-19 < x Initial program 94.2%
*-commutative94.2%
sub-neg94.2%
distribute-rgt-in94.2%
metadata-eval94.2%
neg-mul-194.2%
associate-+r+94.2%
unsub-neg94.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 99.9%
if -3.7e6 < x < 5.20000000000000026e-19Initial 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 99.3%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-73) (not (<= x 7.4e-21))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-73) || !(x <= 7.4e-21)) {
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 <= (-2.7d-73)) .or. (.not. (x <= 7.4d-21))) 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 <= -2.7e-73) || !(x <= 7.4e-21)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-73) or not (x <= 7.4e-21): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-73) || !(x <= 7.4e-21)) 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 <= -2.7e-73) || ~((x <= 7.4e-21))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-73], N[Not[LessEqual[x, 7.4e-21]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-73} \lor \neg \left(x \leq 7.4 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.69999999999999994e-73 or 7.40000000000000041e-21 < x Initial program 94.7%
*-commutative94.7%
sub-neg94.7%
distribute-rgt-in94.8%
metadata-eval94.8%
neg-mul-194.8%
associate-+r+94.8%
unsub-neg94.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 96.3%
if -2.69999999999999994e-73 < x < 7.40000000000000041e-21Initial 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 x around 0 70.0%
neg-mul-170.0%
Simplified70.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-67) (not (<= x 3.2e-45))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-67) || !(x <= 3.2e-45)) {
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 <= (-7d-67)) .or. (.not. (x <= 3.2d-45))) 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 <= -7e-67) || !(x <= 3.2e-45)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e-67) or not (x <= 3.2e-45): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e-67) || !(x <= 3.2e-45)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e-67) || ~((x <= 3.2e-45))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-67], N[Not[LessEqual[x, 3.2e-45]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-67} \lor \neg \left(x \leq 3.2 \cdot 10^{-45}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.0000000000000001e-67 or 3.20000000000000007e-45 < x Initial program 94.7%
*-commutative94.7%
sub-neg94.7%
distribute-rgt-in94.8%
metadata-eval94.8%
neg-mul-194.8%
associate-+r+94.8%
unsub-neg94.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 96.3%
Taylor expanded in y around inf 53.5%
if -7.0000000000000001e-67 < x < 3.20000000000000007e-45Initial 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 x around 0 70.0%
neg-mul-170.0%
Simplified70.0%
Final simplification60.1%
(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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 31.9%
neg-mul-131.9%
Simplified31.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 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 31.9%
neg-mul-131.9%
Simplified31.9%
neg-sub031.9%
sub-neg31.9%
add-sqr-sqrt18.7%
sqrt-unprod16.4%
sqr-neg16.4%
sqrt-unprod1.4%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
+-lft-identity2.6%
Simplified2.6%
herbie shell --seed 2024181
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))