
(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 7 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 (- 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}
Initial program 99.9%
(FPCore (x y) :precision binary64 (if (<= x -3.5e-34) (* (- y x) -0.5) (+ x (/ (fabs y) 2.0))))
double code(double x, double y) {
double tmp;
if (x <= -3.5e-34) {
tmp = (y - x) * -0.5;
} else {
tmp = x + (fabs(y) / 2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.5d-34)) then
tmp = (y - x) * (-0.5d0)
else
tmp = x + (abs(y) / 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.5e-34) {
tmp = (y - x) * -0.5;
} else {
tmp = x + (Math.abs(y) / 2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.5e-34: tmp = (y - x) * -0.5 else: tmp = x + (math.fabs(y) / 2.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -3.5e-34) tmp = Float64(Float64(y - x) * -0.5); else tmp = Float64(x + Float64(abs(y) / 2.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.5e-34) tmp = (y - x) * -0.5; else tmp = x + (abs(y) / 2.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.5e-34], N[(N[(y - x), $MachinePrecision] * -0.5), $MachinePrecision], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-34}:\\
\;\;\;\;\left(y - x\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\end{array}
\end{array}
if x < -3.5e-34Initial program 100.0%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr29.0%
Taylor expanded in y around -inf
associate-*r*N/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-lowering-*.f6459.9%
Simplified59.9%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
cancel-sign-sub-invN/A
metadata-evalN/A
distribute-rgt1-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f6480.5%
Simplified80.5%
if -3.5e-34 < x Initial program 99.9%
Taylor expanded in y around inf
Simplified69.8%
Final simplification73.1%
(FPCore (x y) :precision binary64 (if (<= y -1.2e-151) (* y -0.5) (if (<= y 2.5e-5) (* x 0.5) (* y 0.5))))
double code(double x, double y) {
double tmp;
if (y <= -1.2e-151) {
tmp = y * -0.5;
} else if (y <= 2.5e-5) {
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 <= (-1.2d-151)) then
tmp = y * (-0.5d0)
else if (y <= 2.5d-5) 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 <= -1.2e-151) {
tmp = y * -0.5;
} else if (y <= 2.5e-5) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.2e-151: tmp = y * -0.5 elif y <= 2.5e-5: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.2e-151) tmp = Float64(y * -0.5); elseif (y <= 2.5e-5) 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 <= -1.2e-151) tmp = y * -0.5; elseif (y <= 2.5e-5) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.2e-151], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 2.5e-5], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{-151}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-5}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < -1.2e-151Initial program 100.0%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr35.9%
Taylor expanded in y around -inf
*-commutativeN/A
*-lowering-*.f6463.2%
Simplified63.2%
if -1.2e-151 < y < 2.50000000000000012e-5Initial program 99.9%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr37.8%
Taylor expanded in y around -inf
associate-*r*N/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-lowering-*.f6436.5%
Simplified36.5%
Taylor expanded in y around 0
sub-negN/A
distribute-lft-inN/A
neg-mul-1N/A
remove-double-negN/A
distribute-rgt-outN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f6448.3%
Simplified48.3%
if 2.50000000000000012e-5 < y Initial program 100.0%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr24.0%
Taylor expanded in x around 0
*-lowering-*.f6479.8%
Simplified79.8%
Final simplification62.1%
(FPCore (x y) :precision binary64 (if (<= y 3.8e-5) (* (- y x) -0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 3.8e-5) {
tmp = (y - 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 <= 3.8d-5) then
tmp = (y - 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 <= 3.8e-5) {
tmp = (y - x) * -0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.8e-5: tmp = (y - x) * -0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.8e-5) tmp = Float64(Float64(y - x) * -0.5); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.8e-5) tmp = (y - x) * -0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.8e-5], N[(N[(y - x), $MachinePrecision] * -0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.8 \cdot 10^{-5}:\\
\;\;\;\;\left(y - x\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 3.8000000000000002e-5Initial program 99.9%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr36.9%
Taylor expanded in y around -inf
associate-*r*N/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-lowering-*.f6457.4%
Simplified57.4%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
cancel-sign-sub-invN/A
metadata-evalN/A
distribute-rgt1-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f6466.8%
Simplified66.8%
if 3.8000000000000002e-5 < y Initial program 100.0%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr24.0%
Taylor expanded in x around 0
*-lowering-*.f6479.8%
Simplified79.8%
Final simplification70.4%
(FPCore (x y) :precision binary64 (if (<= y 5.6e-5) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 5.6e-5) {
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 <= 5.6d-5) 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 <= 5.6e-5) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.6e-5: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 5.6e-5) 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 <= 5.6e-5) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.6e-5], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.6 \cdot 10^{-5}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 5.59999999999999992e-5Initial program 99.9%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr36.9%
Taylor expanded in y around -inf
associate-*r*N/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-lowering-*.f6457.4%
Simplified57.4%
Taylor expanded in y around 0
sub-negN/A
distribute-lft-inN/A
neg-mul-1N/A
remove-double-negN/A
distribute-rgt-outN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f6437.0%
Simplified37.0%
if 5.59999999999999992e-5 < y Initial program 100.0%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr24.0%
Taylor expanded in x around 0
*-lowering-*.f6479.8%
Simplified79.8%
Final simplification49.0%
(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%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr33.3%
Taylor expanded in y around -inf
associate-*r*N/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-lowering-*.f6445.3%
Simplified45.3%
Taylor expanded in y around 0
sub-negN/A
distribute-lft-inN/A
neg-mul-1N/A
remove-double-negN/A
distribute-rgt-outN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f6431.1%
Simplified31.1%
Final simplification31.1%
(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
Simplified11.1%
herbie shell --seed 2024149
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))