
(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 96.5%
*-commutative96.5%
sub-neg96.5%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -0.0012) (* x y) (if (<= x 1.2e-45) (- z) (if (<= x 1.9e+30) (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.0012) {
tmp = x * y;
} else if (x <= 1.2e-45) {
tmp = -z;
} else if (x <= 1.9e+30) {
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 <= (-0.0012d0)) then
tmp = x * y
else if (x <= 1.2d-45) then
tmp = -z
else if (x <= 1.9d+30) 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 <= -0.0012) {
tmp = x * y;
} else if (x <= 1.2e-45) {
tmp = -z;
} else if (x <= 1.9e+30) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.0012: tmp = x * y elif x <= 1.2e-45: tmp = -z elif x <= 1.9e+30: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.0012) tmp = Float64(x * y); elseif (x <= 1.2e-45) tmp = Float64(-z); elseif (x <= 1.9e+30) 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 <= -0.0012) tmp = x * y; elseif (x <= 1.2e-45) tmp = -z; elseif (x <= 1.9e+30) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.0012], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.2e-45], (-z), If[LessEqual[x, 1.9e+30], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0012:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-45}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+30}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -0.00119999999999999989 or 1.19999999999999995e-45 < x < 1.9000000000000001e30Initial program 95.3%
*-commutative95.3%
sub-neg95.3%
distribute-rgt-in95.3%
metadata-eval95.3%
neg-mul-195.3%
associate-+r+95.3%
unsub-neg95.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-+r+100.0%
+-commutative100.0%
associate-+l+100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 56.2%
if -0.00119999999999999989 < x < 1.19999999999999995e-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 81.3%
neg-mul-181.3%
Simplified81.3%
if 1.9000000000000001e30 < x Initial program 88.1%
*-commutative88.1%
sub-neg88.1%
distribute-rgt-in88.1%
metadata-eval88.1%
neg-mul-188.1%
associate-+r+88.1%
unsub-neg88.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 58.5%
Taylor expanded in x around inf 58.5%
*-commutative58.5%
Simplified58.5%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e+14) (not (<= x 1.0))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e+14) || !(x <= 1.0)) {
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 <= (-7.5d+14)) .or. (.not. (x <= 1.0d0))) 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 <= -7.5e+14) || !(x <= 1.0)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e+14) or not (x <= 1.0): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e+14) || !(x <= 1.0)) 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 <= -7.5e+14) || ~((x <= 1.0))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e+14], N[Not[LessEqual[x, 1.0]], $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 -7.5 \cdot 10^{+14} \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -7.5e14 or 1 < x Initial program 92.2%
*-commutative92.2%
sub-neg92.2%
distribute-rgt-in92.2%
metadata-eval92.2%
neg-mul-192.2%
associate-+r+92.2%
unsub-neg92.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 99.6%
if -7.5e14 < 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%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 99.0%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0033) (not (<= x 5.9e-42))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0033) || !(x <= 5.9e-42)) {
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 <= (-0.0033d0)) .or. (.not. (x <= 5.9d-42))) 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 <= -0.0033) || !(x <= 5.9e-42)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0033) or not (x <= 5.9e-42): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0033) || !(x <= 5.9e-42)) 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 <= -0.0033) || ~((x <= 5.9e-42))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0033], N[Not[LessEqual[x, 5.9e-42]], $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 -0.0033 \lor \neg \left(x \leq 5.9 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -0.0033 or 5.89999999999999992e-42 < x Initial program 92.9%
*-commutative92.9%
sub-neg92.9%
distribute-rgt-in92.8%
metadata-eval92.8%
neg-mul-192.8%
associate-+r+92.9%
unsub-neg92.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 97.3%
if -0.0033 < x < 5.89999999999999992e-42Initial 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 z around inf 81.7%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0012) (not (<= x 5.8e-42))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0012) || !(x <= 5.8e-42)) {
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 <= (-0.0012d0)) .or. (.not. (x <= 5.8d-42))) 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 <= -0.0012) || !(x <= 5.8e-42)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0012) or not (x <= 5.8e-42): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0012) || !(x <= 5.8e-42)) 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 <= -0.0012) || ~((x <= 5.8e-42))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0012], N[Not[LessEqual[x, 5.8e-42]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0012 \lor \neg \left(x \leq 5.8 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.00119999999999999989 or 5.8000000000000006e-42 < x Initial program 92.9%
*-commutative92.9%
sub-neg92.9%
distribute-rgt-in92.8%
metadata-eval92.8%
neg-mul-192.8%
associate-+r+92.9%
unsub-neg92.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 97.3%
if -0.00119999999999999989 < x < 5.8000000000000006e-42Initial 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 80.9%
neg-mul-180.9%
Simplified80.9%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0012) (not (<= x 1.02e-44))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0012) || !(x <= 1.02e-44)) {
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 <= (-0.0012d0)) .or. (.not. (x <= 1.02d-44))) 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 <= -0.0012) || !(x <= 1.02e-44)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0012) or not (x <= 1.02e-44): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0012) || !(x <= 1.02e-44)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0012) || ~((x <= 1.02e-44))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0012], N[Not[LessEqual[x, 1.02e-44]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0012 \lor \neg \left(x \leq 1.02 \cdot 10^{-44}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.00119999999999999989 or 1.0199999999999999e-44 < x Initial program 93.0%
*-commutative93.0%
sub-neg93.0%
distribute-rgt-in93.0%
metadata-eval93.0%
neg-mul-193.0%
associate-+r+93.0%
unsub-neg93.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-+r+100.0%
+-commutative100.0%
associate-+l+100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 52.1%
if -0.00119999999999999989 < x < 1.0199999999999999e-44Initial 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 81.3%
neg-mul-181.3%
Simplified81.3%
Final simplification66.7%
(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.5%
*-commutative96.5%
sub-neg96.5%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 43.6%
neg-mul-143.6%
Simplified43.6%
(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.5%
*-commutative96.5%
sub-neg96.5%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 43.6%
neg-mul-143.6%
Simplified43.6%
neg-sub043.6%
sub-neg43.6%
add-sqr-sqrt20.0%
sqrt-unprod16.9%
sqr-neg16.9%
sqrt-unprod1.2%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
+-lft-identity2.5%
Simplified2.5%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))