
(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 9 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 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.05e-21) (+ x (/ (fabs y) 2.0)) (if (<= y 2.2e-145) (+ x (/ (fabs x) 2.0)) (* 0.5 (+ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.05e-21) {
tmp = x + (fabs(y) / 2.0);
} else if (y <= 2.2e-145) {
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.05d-21)) then
tmp = x + (abs(y) / 2.0d0)
else if (y <= 2.2d-145) 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.05e-21) {
tmp = x + (Math.abs(y) / 2.0);
} else if (y <= 2.2e-145) {
tmp = x + (Math.abs(x) / 2.0);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e-21: tmp = x + (math.fabs(y) / 2.0) elif y <= 2.2e-145: 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.05e-21) tmp = Float64(x + Float64(abs(y) / 2.0)); elseif (y <= 2.2e-145) 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.05e-21) tmp = x + (abs(y) / 2.0); elseif (y <= 2.2e-145) tmp = x + (abs(x) / 2.0); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e-21], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.2e-145], 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.05 \cdot 10^{-21}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-145}:\\
\;\;\;\;x + \frac{\left|x\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.05000000000000006e-21Initial program 100.0%
Taylor expanded in y around inf 86.0%
if -1.05000000000000006e-21 < y < 2.19999999999999999e-145Initial program 99.9%
Taylor expanded in y around 0 89.2%
neg-mul-189.2%
Simplified89.2%
if 2.19999999999999999e-145 < 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-sqrt82.1%
fabs-sqr82.1%
rem-square-sqrt85.7%
Simplified85.7%
Taylor expanded in x around 0 85.7%
distribute-lft-out85.7%
Simplified85.7%
Final simplification87.1%
(FPCore (x y) :precision binary64 (if (<= x -6.7e-192) (* 0.5 (+ x y)) (if (<= x 9.4e-95) (+ x (/ (fabs y) 2.0)) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -6.7e-192) {
tmp = 0.5 * (x + y);
} else if (x <= 9.4e-95) {
tmp = x + (fabs(y) / 2.0);
} 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 <= (-6.7d-192)) then
tmp = 0.5d0 * (x + y)
else if (x <= 9.4d-95) then
tmp = x + (abs(y) / 2.0d0)
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.7e-192) {
tmp = 0.5 * (x + y);
} else if (x <= 9.4e-95) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.7e-192: tmp = 0.5 * (x + y) elif x <= 9.4e-95: tmp = x + (math.fabs(y) / 2.0) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -6.7e-192) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 9.4e-95) tmp = Float64(x + Float64(abs(y) / 2.0)); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.7e-192) tmp = 0.5 * (x + y); elseif (x <= 9.4e-95) tmp = x + (abs(y) / 2.0); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.7e-192], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.4e-95], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.7 \cdot 10^{-192}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 9.4 \cdot 10^{-95}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -6.69999999999999991e-192Initial 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-sqrt80.6%
fabs-sqr80.6%
rem-square-sqrt81.4%
Simplified81.4%
Taylor expanded in x around 0 81.4%
distribute-lft-out81.4%
Simplified81.4%
if -6.69999999999999991e-192 < x < 9.3999999999999995e-95Initial program 100.0%
Taylor expanded in y around inf 92.1%
if 9.3999999999999995e-95 < x Initial program 99.9%
Taylor expanded in y around 0 71.4%
neg-mul-171.4%
Simplified71.4%
Taylor expanded in x around 0 71.4%
*-rgt-identity71.4%
*-commutative71.4%
fabs-neg71.4%
rem-square-sqrt71.3%
fabs-sqr71.3%
rem-square-sqrt71.4%
distribute-lft-out71.4%
metadata-eval71.4%
Simplified71.4%
(FPCore (x y) :precision binary64 (if (<= x -2.4e-191) (* 0.5 (+ x y)) (if (<= x 9.8e-95) (* (fabs y) 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -2.4e-191) {
tmp = 0.5 * (x + y);
} else if (x <= 9.8e-95) {
tmp = fabs(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 <= (-2.4d-191)) then
tmp = 0.5d0 * (x + y)
else if (x <= 9.8d-95) then
tmp = abs(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 <= -2.4e-191) {
tmp = 0.5 * (x + y);
} else if (x <= 9.8e-95) {
tmp = Math.abs(y) * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.4e-191: tmp = 0.5 * (x + y) elif x <= 9.8e-95: tmp = math.fabs(y) * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -2.4e-191) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 9.8e-95) tmp = Float64(abs(y) * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.4e-191) tmp = 0.5 * (x + y); elseif (x <= 9.8e-95) tmp = abs(y) * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.4e-191], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.8e-95], N[(N[Abs[y], $MachinePrecision] * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-191}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 9.8 \cdot 10^{-95}:\\
\;\;\;\;\left|y\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -2.3999999999999999e-191Initial 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-sqrt80.6%
fabs-sqr80.6%
rem-square-sqrt81.4%
Simplified81.4%
Taylor expanded in x around 0 81.4%
distribute-lft-out81.4%
Simplified81.4%
if -2.3999999999999999e-191 < x < 9.8e-95Initial program 100.0%
Taylor expanded in y around inf 92.1%
Taylor expanded in x around 0 90.9%
if 9.8e-95 < x Initial program 99.9%
Taylor expanded in y around 0 71.4%
neg-mul-171.4%
Simplified71.4%
Taylor expanded in x around 0 71.4%
*-rgt-identity71.4%
*-commutative71.4%
fabs-neg71.4%
rem-square-sqrt71.3%
fabs-sqr71.3%
rem-square-sqrt71.4%
distribute-lft-out71.4%
metadata-eval71.4%
Simplified71.4%
Final simplification80.9%
(FPCore (x y) :precision binary64 (if (<= x -8.5e-175) (* x 0.5) (if (<= x 1.2e-107) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -8.5e-175) {
tmp = x * 0.5;
} else if (x <= 1.2e-107) {
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 <= (-8.5d-175)) then
tmp = x * 0.5d0
else if (x <= 1.2d-107) 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 <= -8.5e-175) {
tmp = x * 0.5;
} else if (x <= 1.2e-107) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -8.5e-175: tmp = x * 0.5 elif x <= 1.2e-107: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -8.5e-175) tmp = Float64(x * 0.5); elseif (x <= 1.2e-107) 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 <= -8.5e-175) tmp = x * 0.5; elseif (x <= 1.2e-107) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -8.5e-175], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 1.2e-107], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-175}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-107}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -8.5000000000000005e-175Initial 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-sqrt79.9%
fabs-sqr79.9%
rem-square-sqrt80.7%
Simplified80.7%
Taylor expanded in x around inf 61.3%
*-commutative61.3%
Simplified61.3%
if -8.5000000000000005e-175 < x < 1.19999999999999997e-107Initial program 100.0%
Taylor expanded in x around 0 88.9%
metadata-eval88.9%
fabs-mul88.9%
*-commutative88.9%
rem-square-sqrt53.4%
fabs-sqr53.4%
rem-square-sqrt54.4%
*-commutative54.4%
Simplified54.4%
Taylor expanded in y around inf 54.7%
*-commutative54.7%
Simplified54.7%
if 1.19999999999999997e-107 < x Initial program 99.9%
Taylor expanded in y around 0 69.8%
neg-mul-169.8%
Simplified69.8%
Taylor expanded in x around 0 69.8%
*-rgt-identity69.8%
*-commutative69.8%
fabs-neg69.8%
rem-square-sqrt69.7%
fabs-sqr69.7%
rem-square-sqrt69.8%
distribute-lft-out69.8%
metadata-eval69.8%
Simplified69.8%
(FPCore (x y) :precision binary64 (if (<= x 9.5e-104) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 9.5e-104) {
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 <= 9.5d-104) 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 <= 9.5e-104) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 9.5e-104: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 9.5e-104) 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 <= 9.5e-104) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 9.5e-104], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.5 \cdot 10^{-104}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 9.5000000000000002e-104Initial 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-sqrt71.9%
fabs-sqr71.9%
rem-square-sqrt73.0%
Simplified73.0%
Taylor expanded in x around 0 73.0%
distribute-lft-out73.0%
Simplified73.0%
if 9.5000000000000002e-104 < x Initial program 99.9%
Taylor expanded in y around 0 69.8%
neg-mul-169.8%
Simplified69.8%
Taylor expanded in x around 0 69.8%
*-rgt-identity69.8%
*-commutative69.8%
fabs-neg69.8%
rem-square-sqrt69.7%
fabs-sqr69.7%
rem-square-sqrt69.8%
distribute-lft-out69.8%
metadata-eval69.8%
Simplified69.8%
(FPCore (x y) :precision binary64 (if (<= x -2e-310) (* x 0.5) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= -2e-310) {
tmp = x * 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 <= (-2d-310)) then
tmp = x * 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 <= -2e-310) {
tmp = x * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2e-310: tmp = x * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -2e-310) tmp = Float64(x * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2e-310) tmp = x * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2e-310], N[(x * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial 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-sqrt79.7%
fabs-sqr79.7%
rem-square-sqrt80.5%
Simplified80.5%
Taylor expanded in x around inf 51.6%
*-commutative51.6%
Simplified51.6%
if -1.999999999999994e-310 < x Initial program 99.9%
Taylor expanded in y around 0 49.9%
neg-mul-149.9%
Simplified49.9%
Taylor expanded in x around 0 49.9%
*-rgt-identity49.9%
*-commutative49.9%
fabs-neg49.9%
rem-square-sqrt49.8%
fabs-sqr49.8%
rem-square-sqrt49.9%
distribute-lft-out49.9%
metadata-eval49.9%
Simplified49.9%
(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 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-sqrt54.3%
fabs-sqr54.3%
rem-square-sqrt59.0%
Simplified59.0%
Taylor expanded in x around inf 31.9%
*-commutative31.9%
Simplified31.9%
(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 100.0%
Taylor expanded in x around inf 11.2%
herbie shell --seed 2024116
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))