
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- x y)) 2.0)))
double code(double x, double y) {
return x + (fabs((x - y)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((x - y)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((x - y)) / 2.0);
}
def code(x, y): return x + (math.fabs((x - y)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(x - y)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((x - y)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|x - y\right|}{2}
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y -1.5e-103) (+ x (/ (fabs y) 2.0)) (if (<= y 2.05e-150) (+ x (/ (fabs x) 2.0)) (* 0.5 (+ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.5e-103) {
tmp = x + (fabs(y) / 2.0);
} else if (y <= 2.05e-150) {
tmp = x + (fabs(x) / 2.0);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.5d-103)) then
tmp = x + (abs(y) / 2.0d0)
else if (y <= 2.05d-150) then
tmp = x + (abs(x) / 2.0d0)
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.5e-103) {
tmp = x + (Math.abs(y) / 2.0);
} else if (y <= 2.05e-150) {
tmp = x + (Math.abs(x) / 2.0);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.5e-103: tmp = x + (math.fabs(y) / 2.0) elif y <= 2.05e-150: tmp = x + (math.fabs(x) / 2.0) else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.5e-103) tmp = Float64(x + Float64(abs(y) / 2.0)); elseif (y <= 2.05e-150) tmp = Float64(x + Float64(abs(x) / 2.0)); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.5e-103) tmp = x + (abs(y) / 2.0); elseif (y <= 2.05e-150) tmp = x + (abs(x) / 2.0); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.5e-103], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.05e-150], N[(x + N[(N[Abs[x], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-103}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{-150}:\\
\;\;\;\;x + \frac{\left|x\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.5e-103Initial program 100.0%
Taylor expanded in y around inf 80.6%
if -1.5e-103 < y < 2.0499999999999999e-150Initial program 99.9%
Taylor expanded in y around 0 92.1%
neg-mul-192.1%
Simplified92.1%
if 2.0499999999999999e-150 < y Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt86.5%
fabs-sqr86.5%
rem-square-sqrt89.5%
Simplified89.5%
Taylor expanded in x around 0 89.5%
distribute-lft-out89.5%
+-commutative89.5%
Simplified89.5%
Final simplification87.5%
(FPCore (x y) :precision binary64 (if (<= x -3.2e-28) (* 0.5 (+ x y)) (if (<= x 1.9e+19) (+ x (/ (fabs y) 2.0)) (fabs (* x 1.5)))))
double code(double x, double y) {
double tmp;
if (x <= -3.2e-28) {
tmp = 0.5 * (x + y);
} else if (x <= 1.9e+19) {
tmp = x + (fabs(y) / 2.0);
} else {
tmp = fabs((x * 1.5));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.2d-28)) then
tmp = 0.5d0 * (x + y)
else if (x <= 1.9d+19) then
tmp = x + (abs(y) / 2.0d0)
else
tmp = abs((x * 1.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.2e-28) {
tmp = 0.5 * (x + y);
} else if (x <= 1.9e+19) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = Math.abs((x * 1.5));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.2e-28: tmp = 0.5 * (x + y) elif x <= 1.9e+19: tmp = x + (math.fabs(y) / 2.0) else: tmp = math.fabs((x * 1.5)) return tmp
function code(x, y) tmp = 0.0 if (x <= -3.2e-28) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 1.9e+19) tmp = Float64(x + Float64(abs(y) / 2.0)); else tmp = abs(Float64(x * 1.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.2e-28) tmp = 0.5 * (x + y); elseif (x <= 1.9e+19) tmp = x + (abs(y) / 2.0); else tmp = abs((x * 1.5)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.2e-28], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.9e+19], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[Abs[N[(x * 1.5), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-28}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+19}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;\left|x \cdot 1.5\right|\\
\end{array}
\end{array}
if x < -3.19999999999999982e-28Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt87.7%
fabs-sqr87.7%
rem-square-sqrt88.3%
Simplified88.3%
Taylor expanded in x around 0 88.4%
distribute-lft-out88.4%
+-commutative88.4%
Simplified88.4%
if -3.19999999999999982e-28 < x < 1.9e19Initial program 100.0%
Taylor expanded in y around inf 82.8%
if 1.9e19 < x Initial program 99.8%
Taylor expanded in y around 0 81.3%
neg-mul-181.3%
Simplified81.3%
add-sqr-sqrt81.1%
pow281.1%
div-inv81.1%
fabs-neg81.1%
add-sqr-sqrt81.0%
fabs-sqr81.0%
add-sqr-sqrt81.1%
metadata-eval81.1%
Applied egg-rr81.1%
flip-+40.4%
div-inv40.2%
Applied egg-rr43.8%
metadata-eval43.8%
associate-/r*43.8%
*-commutative43.8%
div-inv44.0%
associate-/l*81.3%
*-inverses81.3%
associate-*l*81.3%
metadata-eval81.3%
add-sqr-sqrt80.8%
sqrt-unprod44.0%
swap-sqr43.9%
pow243.9%
metadata-eval43.9%
Applied egg-rr43.9%
unpow243.9%
metadata-eval43.9%
swap-sqr44.0%
rem-sqrt-square81.3%
*-commutative81.3%
Simplified81.3%
Final simplification84.2%
(FPCore (x y) :precision binary64 (if (<= x -1.22e-27) (* x 0.5) (if (<= x 1.45e-109) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -1.22e-27) {
tmp = x * 0.5;
} else if (x <= 1.45e-109) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.22d-27)) then
tmp = x * 0.5d0
else if (x <= 1.45d-109) then
tmp = y * 0.5d0
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.22e-27) {
tmp = x * 0.5;
} else if (x <= 1.45e-109) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.22e-27: tmp = x * 0.5 elif x <= 1.45e-109: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.22e-27) tmp = Float64(x * 0.5); elseif (x <= 1.45e-109) tmp = Float64(y * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.22e-27) tmp = x * 0.5; elseif (x <= 1.45e-109) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.22e-27], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 1.45e-109], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{-27}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-109}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -1.22e-27Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt87.7%
fabs-sqr87.7%
rem-square-sqrt88.3%
Simplified88.3%
Taylor expanded in x around inf 73.9%
if -1.22e-27 < x < 1.45e-109Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt48.6%
fabs-sqr48.6%
rem-square-sqrt50.3%
Simplified50.3%
Taylor expanded in x around 0 41.2%
if 1.45e-109 < x Initial program 99.8%
Taylor expanded in y around 0 65.8%
neg-mul-165.8%
Simplified65.8%
add-sqr-sqrt65.6%
pow265.6%
div-inv65.6%
fabs-neg65.6%
add-sqr-sqrt65.6%
fabs-sqr65.6%
add-sqr-sqrt65.6%
metadata-eval65.6%
Applied egg-rr65.6%
Taylor expanded in x around 0 65.8%
+-commutative65.8%
unpow265.8%
rem-square-sqrt65.8%
metadata-eval65.8%
Simplified65.8%
Final simplification59.0%
(FPCore (x y) :precision binary64 (if (<= x 1.35e-71) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 1.35e-71) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.35d-71) then
tmp = 0.5d0 * (x + y)
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.35e-71) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.35e-71: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 1.35e-71) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.35e-71) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.35e-71], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{-71}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 1.3500000000000001e-71Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt65.1%
fabs-sqr65.1%
rem-square-sqrt66.6%
Simplified66.6%
Taylor expanded in x around 0 66.6%
distribute-lft-out66.6%
+-commutative66.6%
Simplified66.6%
if 1.3500000000000001e-71 < x Initial program 99.8%
Taylor expanded in y around 0 67.6%
neg-mul-167.6%
Simplified67.6%
add-sqr-sqrt67.5%
pow267.5%
div-inv67.5%
fabs-neg67.5%
add-sqr-sqrt67.4%
fabs-sqr67.4%
add-sqr-sqrt67.5%
metadata-eval67.5%
Applied egg-rr67.5%
Taylor expanded in x around 0 67.6%
+-commutative67.6%
unpow267.6%
rem-square-sqrt67.6%
metadata-eval67.6%
Simplified67.6%
Final simplification66.9%
(FPCore (x y) :precision binary64 (if (<= y 8.4e-128) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 8.4e-128) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 8.4d-128) then
tmp = x * 0.5d0
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8.4e-128) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.4e-128: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 8.4e-128) tmp = Float64(x * 0.5); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.4e-128) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.4e-128], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.4 \cdot 10^{-128}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 8.4000000000000004e-128Initial program 99.9%
Taylor expanded in y around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-sub99.9%
rem-square-sqrt31.7%
fabs-sqr31.7%
rem-square-sqrt37.2%
Simplified37.2%
Taylor expanded in x around inf 36.4%
if 8.4000000000000004e-128 < y Initial program 99.9%
Taylor expanded in y around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-sub99.9%
rem-square-sqrt85.9%
fabs-sqr85.9%
rem-square-sqrt89.0%
Simplified89.0%
Taylor expanded in x around 0 69.5%
Final simplification48.1%
(FPCore (x y) :precision binary64 (* x 0.5))
double code(double x, double y) {
return x * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 0.5d0
end function
public static double code(double x, double y) {
return x * 0.5;
}
def code(x, y): return x * 0.5
function code(x, y) return Float64(x * 0.5) end
function tmp = code(x, y) tmp = x * 0.5; end
code[x_, y_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 99.9%
Taylor expanded in y around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-sub99.9%
rem-square-sqrt50.8%
fabs-sqr50.8%
rem-square-sqrt55.4%
Simplified55.4%
Taylor expanded in x around inf 31.0%
Final simplification31.0%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 10.9%
herbie shell --seed 2024111
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))