
(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 (- 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%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (- y x) 0.5)))
(if (<= x -1.15e-17)
(* 0.5 (+ x y))
(if (or (<= x 2.8e+20) (not (<= x 1e+138)))
(* (fabs (- y x)) 0.5)
(/ (- (* t_0 t_0) (* x x)) (+ (* y -0.5) (* x -0.5)))))))
double code(double x, double y) {
double t_0 = (y - x) * 0.5;
double tmp;
if (x <= -1.15e-17) {
tmp = 0.5 * (x + y);
} else if ((x <= 2.8e+20) || !(x <= 1e+138)) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = (y - x) * 0.5d0
if (x <= (-1.15d-17)) then
tmp = 0.5d0 * (x + y)
else if ((x <= 2.8d+20) .or. (.not. (x <= 1d+138))) then
tmp = abs((y - x)) * 0.5d0
else
tmp = ((t_0 * t_0) - (x * x)) / ((y * (-0.5d0)) + (x * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y - x) * 0.5;
double tmp;
if (x <= -1.15e-17) {
tmp = 0.5 * (x + y);
} else if ((x <= 2.8e+20) || !(x <= 1e+138)) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
}
return tmp;
}
def code(x, y): t_0 = (y - x) * 0.5 tmp = 0 if x <= -1.15e-17: tmp = 0.5 * (x + y) elif (x <= 2.8e+20) or not (x <= 1e+138): tmp = math.fabs((y - x)) * 0.5 else: tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5)) return tmp
function code(x, y) t_0 = Float64(Float64(y - x) * 0.5) tmp = 0.0 if (x <= -1.15e-17) tmp = Float64(0.5 * Float64(x + y)); elseif ((x <= 2.8e+20) || !(x <= 1e+138)) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(Float64(y * -0.5) + Float64(x * -0.5))); end return tmp end
function tmp_2 = code(x, y) t_0 = (y - x) * 0.5; tmp = 0.0; if (x <= -1.15e-17) tmp = 0.5 * (x + y); elseif ((x <= 2.8e+20) || ~((x <= 1e+138))) tmp = abs((y - x)) * 0.5; else tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[x, -1.15e-17], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, 2.8e+20], N[Not[LessEqual[x, 1e+138]], $MachinePrecision]], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(y * -0.5), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot 0.5\\
\mathbf{if}\;x \leq -1.15 \cdot 10^{-17}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+20} \lor \neg \left(x \leq 10^{+138}\right):\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\
\end{array}
\end{array}
if x < -1.15000000000000004e-17Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt90.5%
fabs-sqr90.5%
add-sqr-sqrt91.3%
metadata-eval91.3%
Applied egg-rr91.3%
Taylor expanded in y around 0 91.3%
+-commutative91.3%
associate-+r+91.3%
distribute-lft1-in91.3%
metadata-eval91.3%
distribute-lft-out91.3%
Simplified91.3%
if -1.15000000000000004e-17 < x < 2.8e20 or 1e138 < x Initial program 99.9%
Taylor expanded in x around 0 74.9%
if 2.8e20 < x < 1e138Initial program 99.6%
+-commutative99.6%
div-inv99.6%
fma-def99.6%
add-sqr-sqrt3.8%
fabs-sqr3.8%
add-sqr-sqrt16.9%
metadata-eval16.9%
Applied egg-rr16.9%
fma-udef16.9%
flip-+13.3%
Applied egg-rr13.3%
add-sqr-sqrt0.2%
sqrt-prod87.9%
associate-*r*87.9%
sqrt-prod87.5%
fma-neg87.5%
*-commutative87.5%
associate-*l*87.5%
pow287.5%
Applied egg-rr87.5%
Taylor expanded in y around -inf 87.4%
sub-neg87.4%
+-commutative87.4%
associate-+l+87.4%
*-commutative87.4%
*-commutative87.4%
unpow287.4%
rem-square-sqrt87.7%
associate-*l*87.7%
metadata-eval87.7%
unpow287.7%
rem-square-sqrt88.5%
neg-mul-188.5%
distribute-rgt-out88.5%
metadata-eval88.5%
Simplified88.5%
Final simplification80.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (- y x) 0.5)))
(if (<= y -5e+131)
(* (/ y 0.5) -0.25)
(if (or (<= y -7.7e-149) (and (not (<= y 1.35e-96)) (<= y 3.1e-87)))
(/ (- (* t_0 t_0) (* x x)) (+ (* y -0.5) (* x -0.5)))
(* 0.5 (+ x y))))))
double code(double x, double y) {
double t_0 = (y - x) * 0.5;
double tmp;
if (y <= -5e+131) {
tmp = (y / 0.5) * -0.25;
} else if ((y <= -7.7e-149) || (!(y <= 1.35e-96) && (y <= 3.1e-87))) {
tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
} 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) :: t_0
real(8) :: tmp
t_0 = (y - x) * 0.5d0
if (y <= (-5d+131)) then
tmp = (y / 0.5d0) * (-0.25d0)
else if ((y <= (-7.7d-149)) .or. (.not. (y <= 1.35d-96)) .and. (y <= 3.1d-87)) then
tmp = ((t_0 * t_0) - (x * x)) / ((y * (-0.5d0)) + (x * (-0.5d0)))
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y - x) * 0.5;
double tmp;
if (y <= -5e+131) {
tmp = (y / 0.5) * -0.25;
} else if ((y <= -7.7e-149) || (!(y <= 1.35e-96) && (y <= 3.1e-87))) {
tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): t_0 = (y - x) * 0.5 tmp = 0 if y <= -5e+131: tmp = (y / 0.5) * -0.25 elif (y <= -7.7e-149) or (not (y <= 1.35e-96) and (y <= 3.1e-87)): tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5)) else: tmp = 0.5 * (x + y) return tmp
function code(x, y) t_0 = Float64(Float64(y - x) * 0.5) tmp = 0.0 if (y <= -5e+131) tmp = Float64(Float64(y / 0.5) * -0.25); elseif ((y <= -7.7e-149) || (!(y <= 1.35e-96) && (y <= 3.1e-87))) tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(Float64(y * -0.5) + Float64(x * -0.5))); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) t_0 = (y - x) * 0.5; tmp = 0.0; if (y <= -5e+131) tmp = (y / 0.5) * -0.25; elseif ((y <= -7.7e-149) || (~((y <= 1.35e-96)) && (y <= 3.1e-87))) tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5)); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[y, -5e+131], N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision], If[Or[LessEqual[y, -7.7e-149], And[N[Not[LessEqual[y, 1.35e-96]], $MachinePrecision], LessEqual[y, 3.1e-87]]], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(y * -0.5), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot 0.5\\
\mathbf{if}\;y \leq -5 \cdot 10^{+131}:\\
\;\;\;\;\frac{y}{0.5} \cdot -0.25\\
\mathbf{elif}\;y \leq -7.7 \cdot 10^{-149} \lor \neg \left(y \leq 1.35 \cdot 10^{-96}\right) \land y \leq 3.1 \cdot 10^{-87}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -4.99999999999999995e131Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt7.9%
fabs-sqr7.9%
add-sqr-sqrt9.1%
metadata-eval9.1%
Applied egg-rr9.1%
fma-udef9.1%
flip-+0.2%
Applied egg-rr0.2%
add-sqr-sqrt0.0%
sqrt-prod13.1%
associate-*r*13.1%
sqrt-prod13.1%
fma-neg13.1%
*-commutative13.1%
associate-*l*13.1%
pow213.1%
Applied egg-rr13.1%
Taylor expanded in y around -inf 85.6%
*-commutative85.6%
unpow285.6%
rem-square-sqrt87.3%
Simplified87.3%
if -4.99999999999999995e131 < y < -7.70000000000000025e-149 or 1.35e-96 < y < 3.09999999999999998e-87Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt20.8%
fabs-sqr20.8%
add-sqr-sqrt25.4%
metadata-eval25.4%
Applied egg-rr25.4%
fma-udef25.4%
flip-+15.4%
Applied egg-rr15.4%
add-sqr-sqrt11.9%
sqrt-prod84.8%
associate-*r*84.8%
sqrt-prod84.3%
fma-neg84.3%
*-commutative84.3%
associate-*l*84.3%
pow284.3%
Applied egg-rr84.3%
Taylor expanded in y around -inf 73.8%
sub-neg73.8%
+-commutative73.8%
associate-+l+73.8%
*-commutative73.8%
*-commutative73.8%
unpow273.8%
rem-square-sqrt74.9%
associate-*l*74.9%
metadata-eval74.9%
unpow274.9%
rem-square-sqrt74.9%
neg-mul-174.9%
distribute-rgt-out74.9%
metadata-eval74.9%
Simplified74.9%
if -7.70000000000000025e-149 < y < 1.35e-96 or 3.09999999999999998e-87 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt72.1%
fabs-sqr72.1%
add-sqr-sqrt77.4%
metadata-eval77.4%
Applied egg-rr77.4%
Taylor expanded in y around 0 77.4%
+-commutative77.4%
associate-+r+77.4%
distribute-lft1-in77.4%
metadata-eval77.4%
distribute-lft-out77.4%
Simplified77.4%
Final simplification78.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (- y x) 0.5)))
(if (<= y -3.9e+21)
(* (/ y 0.5) -0.25)
(if (<= y -1.9e-28)
(* x 0.5)
(if (<= y -5e-93)
(/ (- (* t_0 t_0) (* x x)) (* y -0.5))
(* 0.5 (+ x y)))))))
double code(double x, double y) {
double t_0 = (y - x) * 0.5;
double tmp;
if (y <= -3.9e+21) {
tmp = (y / 0.5) * -0.25;
} else if (y <= -1.9e-28) {
tmp = x * 0.5;
} else if (y <= -5e-93) {
tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5);
} 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) :: t_0
real(8) :: tmp
t_0 = (y - x) * 0.5d0
if (y <= (-3.9d+21)) then
tmp = (y / 0.5d0) * (-0.25d0)
else if (y <= (-1.9d-28)) then
tmp = x * 0.5d0
else if (y <= (-5d-93)) then
tmp = ((t_0 * t_0) - (x * x)) / (y * (-0.5d0))
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y - x) * 0.5;
double tmp;
if (y <= -3.9e+21) {
tmp = (y / 0.5) * -0.25;
} else if (y <= -1.9e-28) {
tmp = x * 0.5;
} else if (y <= -5e-93) {
tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): t_0 = (y - x) * 0.5 tmp = 0 if y <= -3.9e+21: tmp = (y / 0.5) * -0.25 elif y <= -1.9e-28: tmp = x * 0.5 elif y <= -5e-93: tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5) else: tmp = 0.5 * (x + y) return tmp
function code(x, y) t_0 = Float64(Float64(y - x) * 0.5) tmp = 0.0 if (y <= -3.9e+21) tmp = Float64(Float64(y / 0.5) * -0.25); elseif (y <= -1.9e-28) tmp = Float64(x * 0.5); elseif (y <= -5e-93) tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(y * -0.5)); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) t_0 = (y - x) * 0.5; tmp = 0.0; if (y <= -3.9e+21) tmp = (y / 0.5) * -0.25; elseif (y <= -1.9e-28) tmp = x * 0.5; elseif (y <= -5e-93) tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[y, -3.9e+21], N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision], If[LessEqual[y, -1.9e-28], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, -5e-93], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(y * -0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot 0.5\\
\mathbf{if}\;y \leq -3.9 \cdot 10^{+21}:\\
\;\;\;\;\frac{y}{0.5} \cdot -0.25\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{-28}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-93}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -3.9e21Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt6.1%
fabs-sqr6.1%
add-sqr-sqrt7.5%
metadata-eval7.5%
Applied egg-rr7.5%
fma-udef7.5%
flip-+2.0%
Applied egg-rr2.0%
add-sqr-sqrt1.5%
sqrt-prod47.6%
associate-*r*47.6%
sqrt-prod47.3%
fma-neg47.3%
*-commutative47.3%
associate-*l*47.3%
pow247.3%
Applied egg-rr47.3%
Taylor expanded in y around -inf 85.6%
*-commutative85.6%
unpow285.6%
rem-square-sqrt87.4%
Simplified87.4%
if -3.9e21 < y < -1.90000000000000005e-28Initial program 99.7%
+-commutative99.7%
div-inv99.7%
fma-def99.7%
add-sqr-sqrt49.8%
fabs-sqr49.8%
add-sqr-sqrt55.4%
metadata-eval55.4%
Applied egg-rr55.4%
Taylor expanded in y around 0 56.1%
distribute-lft1-in56.1%
metadata-eval56.1%
*-commutative56.1%
Simplified56.1%
if -1.90000000000000005e-28 < y < -4.99999999999999994e-93Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt18.0%
fabs-sqr18.0%
add-sqr-sqrt22.7%
metadata-eval22.7%
Applied egg-rr22.7%
fma-udef22.7%
flip-+20.9%
Applied egg-rr20.9%
add-sqr-sqrt18.0%
sqrt-prod90.5%
associate-*r*90.5%
sqrt-prod90.1%
fma-neg90.1%
*-commutative90.1%
associate-*l*90.1%
pow290.1%
Applied egg-rr90.1%
Taylor expanded in y around -inf 63.6%
*-commutative63.6%
*-commutative63.6%
unpow263.6%
rem-square-sqrt64.9%
associate-*l*64.9%
metadata-eval64.9%
Simplified64.9%
if -4.99999999999999994e-93 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt68.0%
fabs-sqr68.0%
add-sqr-sqrt73.6%
metadata-eval73.6%
Applied egg-rr73.6%
Taylor expanded in y around 0 73.6%
+-commutative73.6%
associate-+r+73.6%
distribute-lft1-in73.6%
metadata-eval73.6%
distribute-lft-out73.6%
Simplified73.6%
Final simplification75.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (/ y 0.5) -0.25)))
(if (<= y -1.25e+20)
t_0
(if (<= y -1.85e-28)
(* x 0.5)
(if (<= y -4.3e-96) t_0 (* 0.5 (+ x y)))))))
double code(double x, double y) {
double t_0 = (y / 0.5) * -0.25;
double tmp;
if (y <= -1.25e+20) {
tmp = t_0;
} else if (y <= -1.85e-28) {
tmp = x * 0.5;
} else if (y <= -4.3e-96) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (y / 0.5d0) * (-0.25d0)
if (y <= (-1.25d+20)) then
tmp = t_0
else if (y <= (-1.85d-28)) then
tmp = x * 0.5d0
else if (y <= (-4.3d-96)) then
tmp = t_0
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y / 0.5) * -0.25;
double tmp;
if (y <= -1.25e+20) {
tmp = t_0;
} else if (y <= -1.85e-28) {
tmp = x * 0.5;
} else if (y <= -4.3e-96) {
tmp = t_0;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): t_0 = (y / 0.5) * -0.25 tmp = 0 if y <= -1.25e+20: tmp = t_0 elif y <= -1.85e-28: tmp = x * 0.5 elif y <= -4.3e-96: tmp = t_0 else: tmp = 0.5 * (x + y) return tmp
function code(x, y) t_0 = Float64(Float64(y / 0.5) * -0.25) tmp = 0.0 if (y <= -1.25e+20) tmp = t_0; elseif (y <= -1.85e-28) tmp = Float64(x * 0.5); elseif (y <= -4.3e-96) tmp = t_0; else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) t_0 = (y / 0.5) * -0.25; tmp = 0.0; if (y <= -1.25e+20) tmp = t_0; elseif (y <= -1.85e-28) tmp = x * 0.5; elseif (y <= -4.3e-96) tmp = t_0; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision]}, If[LessEqual[y, -1.25e+20], t$95$0, If[LessEqual[y, -1.85e-28], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, -4.3e-96], t$95$0, N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{0.5} \cdot -0.25\\
\mathbf{if}\;y \leq -1.25 \cdot 10^{+20}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.85 \cdot 10^{-28}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq -4.3 \cdot 10^{-96}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.25e20 or -1.8500000000000001e-28 < y < -4.2999999999999998e-96Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt7.8%
fabs-sqr7.8%
add-sqr-sqrt9.7%
metadata-eval9.7%
Applied egg-rr9.7%
fma-udef9.7%
flip-+4.8%
Applied egg-rr4.8%
add-sqr-sqrt3.9%
sqrt-prod53.8%
associate-*r*53.8%
sqrt-prod53.5%
fma-neg53.5%
*-commutative53.5%
associate-*l*53.5%
pow253.5%
Applied egg-rr53.5%
Taylor expanded in y around -inf 82.4%
*-commutative82.4%
unpow282.4%
rem-square-sqrt84.1%
Simplified84.1%
if -1.25e20 < y < -1.8500000000000001e-28Initial program 99.7%
+-commutative99.7%
div-inv99.7%
fma-def99.7%
add-sqr-sqrt49.8%
fabs-sqr49.8%
add-sqr-sqrt55.4%
metadata-eval55.4%
Applied egg-rr55.4%
Taylor expanded in y around 0 56.1%
distribute-lft1-in56.1%
metadata-eval56.1%
*-commutative56.1%
Simplified56.1%
if -4.2999999999999998e-96 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt68.0%
fabs-sqr68.0%
add-sqr-sqrt73.6%
metadata-eval73.6%
Applied egg-rr73.6%
Taylor expanded in y around 0 73.6%
+-commutative73.6%
associate-+r+73.6%
distribute-lft1-in73.6%
metadata-eval73.6%
distribute-lft-out73.6%
Simplified73.6%
Final simplification75.8%
(FPCore (x y) :precision binary64 (if (<= y 2e-211) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2e-211) {
tmp = x;
} 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 <= 2d-211) then
tmp = x
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2e-211) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e-211: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 2e-211) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e-211) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e-211], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-211}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 2.00000000000000017e-211Initial program 99.9%
Taylor expanded in x around inf 11.6%
if 2.00000000000000017e-211 < y Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt78.3%
fabs-sqr78.3%
add-sqr-sqrt82.7%
metadata-eval82.7%
Applied egg-rr82.7%
Taylor expanded in y around inf 63.7%
Final simplification31.9%
(FPCore (x y) :precision binary64 (if (<= y 9.5e-190) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 9.5e-190) {
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 <= 9.5d-190) 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 <= 9.5e-190) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 9.5e-190: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 9.5e-190) 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 <= 9.5e-190) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 9.5e-190], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{-190}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 9.50000000000000055e-190Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt30.5%
fabs-sqr30.5%
add-sqr-sqrt35.0%
metadata-eval35.0%
Applied egg-rr35.0%
Taylor expanded in y around 0 35.1%
distribute-lft1-in35.1%
metadata-eval35.1%
*-commutative35.1%
Simplified35.1%
if 9.50000000000000055e-190 < y Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt78.3%
fabs-sqr78.3%
add-sqr-sqrt82.7%
metadata-eval82.7%
Applied egg-rr82.7%
Taylor expanded in y around inf 63.7%
Final simplification46.3%
(FPCore (x y) :precision binary64 (* 0.5 (+ x y)))
double code(double x, double y) {
return 0.5 * (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * (x + y)
end function
public static double code(double x, double y) {
return 0.5 * (x + y);
}
def code(x, y): return 0.5 * (x + y)
function code(x, y) return Float64(0.5 * Float64(x + y)) end
function tmp = code(x, y) tmp = 0.5 * (x + y); end
code[x_, y_] := N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x + y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt49.2%
fabs-sqr49.2%
add-sqr-sqrt53.7%
metadata-eval53.7%
Applied egg-rr53.7%
Taylor expanded in y around 0 53.6%
+-commutative53.6%
associate-+r+53.7%
distribute-lft1-in53.7%
metadata-eval53.7%
distribute-lft-out53.7%
Simplified53.7%
Final simplification53.7%
(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.7%
Final simplification10.7%
herbie shell --seed 2023240
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))