
(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 97.7%
*-commutative97.7%
sub-neg97.7%
distribute-rgt-in97.7%
metadata-eval97.7%
neg-mul-197.7%
associate-+r+97.7%
unsub-neg97.7%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -4.5e+163)
(* x z)
(if (<= x -3.6e-34)
(* x y)
(if (<= x 1.55e-22) (- z) (if (<= x 1.12e+60) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e+163) {
tmp = x * z;
} else if (x <= -3.6e-34) {
tmp = x * y;
} else if (x <= 1.55e-22) {
tmp = -z;
} else if (x <= 1.12e+60) {
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 <= (-4.5d+163)) then
tmp = x * z
else if (x <= (-3.6d-34)) then
tmp = x * y
else if (x <= 1.55d-22) then
tmp = -z
else if (x <= 1.12d+60) 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 <= -4.5e+163) {
tmp = x * z;
} else if (x <= -3.6e-34) {
tmp = x * y;
} else if (x <= 1.55e-22) {
tmp = -z;
} else if (x <= 1.12e+60) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.5e+163: tmp = x * z elif x <= -3.6e-34: tmp = x * y elif x <= 1.55e-22: tmp = -z elif x <= 1.12e+60: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.5e+163) tmp = Float64(x * z); elseif (x <= -3.6e-34) tmp = Float64(x * y); elseif (x <= 1.55e-22) tmp = Float64(-z); elseif (x <= 1.12e+60) 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 <= -4.5e+163) tmp = x * z; elseif (x <= -3.6e-34) tmp = x * y; elseif (x <= 1.55e-22) tmp = -z; elseif (x <= 1.12e+60) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.5e+163], N[(x * z), $MachinePrecision], If[LessEqual[x, -3.6e-34], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.55e-22], (-z), If[LessEqual[x, 1.12e+60], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+163}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3.6 \cdot 10^{-34}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-22}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.12 \cdot 10^{+60}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -4.49999999999999988e163 or 1.1199999999999999e60 < x Initial program 93.7%
*-commutative93.7%
sub-neg93.7%
distribute-rgt-in93.7%
metadata-eval93.7%
neg-mul-193.7%
associate-+r+93.7%
unsub-neg93.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 66.9%
Taylor expanded in x around inf 66.9%
*-commutative66.9%
Simplified66.9%
if -4.49999999999999988e163 < x < -3.60000000000000008e-34 or 1.55000000000000006e-22 < x < 1.1199999999999999e60Initial program 98.3%
*-commutative98.3%
sub-neg98.3%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 70.3%
Taylor expanded in x around inf 61.6%
if -3.60000000000000008e-34 < x < 1.55000000000000006e-22Initial 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 72.7%
neg-mul-172.7%
Simplified72.7%
Final simplification68.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e+16) (not (<= x 1.35e-15))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+16) || !(x <= 1.35e-15)) {
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 <= (-9d+16)) .or. (.not. (x <= 1.35d-15))) 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 <= -9e+16) || !(x <= 1.35e-15)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e+16) or not (x <= 1.35e-15): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e+16) || !(x <= 1.35e-15)) 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 <= -9e+16) || ~((x <= 1.35e-15))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e+16], N[Not[LessEqual[x, 1.35e-15]], $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 -9 \cdot 10^{+16} \lor \neg \left(x \leq 1.35 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -9e16 or 1.35000000000000005e-15 < x Initial program 95.1%
*-commutative95.1%
sub-neg95.1%
distribute-rgt-in95.1%
metadata-eval95.1%
neg-mul-195.1%
associate-+r+95.1%
unsub-neg95.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 99.4%
if -9e16 < x < 1.35000000000000005e-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 99.3%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.85e-32) (not (<= x 1.25e-22))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.85e-32) || !(x <= 1.25e-22)) {
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 <= (-4.85d-32)) .or. (.not. (x <= 1.25d-22))) 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 <= -4.85e-32) || !(x <= 1.25e-22)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.85e-32) or not (x <= 1.25e-22): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.85e-32) || !(x <= 1.25e-22)) 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 <= -4.85e-32) || ~((x <= 1.25e-22))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.85e-32], N[Not[LessEqual[x, 1.25e-22]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.85 \cdot 10^{-32} \lor \neg \left(x \leq 1.25 \cdot 10^{-22}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.85000000000000003e-32 or 1.24999999999999988e-22 < x Initial program 95.7%
*-commutative95.7%
sub-neg95.7%
distribute-rgt-in95.7%
metadata-eval95.7%
neg-mul-195.7%
associate-+r+95.7%
unsub-neg95.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 95.6%
if -4.85000000000000003e-32 < x < 1.24999999999999988e-22Initial 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 72.7%
neg-mul-172.7%
Simplified72.7%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.15e-35) (not (<= x 1.5e-22))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.15e-35) || !(x <= 1.5e-22)) {
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.15d-35)) .or. (.not. (x <= 1.5d-22))) 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.15e-35) || !(x <= 1.5e-22)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.15e-35) or not (x <= 1.5e-22): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.15e-35) || !(x <= 1.5e-22)) 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.15e-35) || ~((x <= 1.5e-22))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.15e-35], N[Not[LessEqual[x, 1.5e-22]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-35} \lor \neg \left(x \leq 1.5 \cdot 10^{-22}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.1500000000000001e-35 or 1.5e-22 < x Initial program 95.7%
*-commutative95.7%
sub-neg95.7%
distribute-rgt-in95.7%
metadata-eval95.7%
neg-mul-195.7%
associate-+r+95.7%
unsub-neg95.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 55.1%
Taylor expanded in x around inf 51.1%
if -2.1500000000000001e-35 < x < 1.5e-22Initial 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 72.7%
neg-mul-172.7%
Simplified72.7%
Final simplification60.8%
(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.7%
*-commutative97.7%
sub-neg97.7%
distribute-rgt-in97.7%
metadata-eval97.7%
neg-mul-197.7%
associate-+r+97.7%
unsub-neg97.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 36.6%
neg-mul-136.6%
Simplified36.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 97.7%
*-commutative97.7%
sub-neg97.7%
distribute-rgt-in97.7%
metadata-eval97.7%
neg-mul-197.7%
associate-+r+97.7%
unsub-neg97.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 36.6%
neg-mul-136.6%
Simplified36.6%
neg-sub036.6%
sub-neg36.6%
add-sqr-sqrt20.0%
sqrt-unprod21.7%
sqr-neg21.7%
sqrt-unprod1.4%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
+-lft-identity2.7%
Simplified2.7%
herbie shell --seed 2024165
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))