
(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 10 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 (+ (/ (fabs (fma y (/ y (+ y x)) (* (- x) (/ x (+ y x))))) 2.0) x))
double code(double x, double y) {
return (fabs(fma(y, (y / (y + x)), (-x * (x / (y + x))))) / 2.0) + x;
}
function code(x, y) return Float64(Float64(abs(fma(y, Float64(y / Float64(y + x)), Float64(Float64(-x) * Float64(x / Float64(y + x))))) / 2.0) + x) end
code[x_, y_] := N[(N[(N[Abs[N[(y * N[(y / N[(y + x), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\mathsf{fma}\left(y, \frac{y}{y + x}, \left(-x\right) \cdot \frac{x}{y + x}\right)\right|}{2} + x
\end{array}
Initial program 99.9%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (+ (/ (fabs (- y x)) 2.0) x) -5e-201) (* 0.5 x) (fma (- y x) -0.5 x)))
double code(double x, double y) {
double tmp;
if (((fabs((y - x)) / 2.0) + x) <= -5e-201) {
tmp = 0.5 * x;
} else {
tmp = fma((y - x), -0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(abs(Float64(y - x)) / 2.0) + x) <= -5e-201) tmp = Float64(0.5 * x); else tmp = fma(Float64(y - x), -0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] + x), $MachinePrecision], -5e-201], N[(0.5 * x), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left|y - x\right|}{2} + x \leq -5 \cdot 10^{-201}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < -4.9999999999999999e-201Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f641.0
Applied rewrites1.0%
Applied rewrites99.4%
Taylor expanded in y around 0
Applied rewrites99.4%
if -4.9999999999999999e-201 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.8%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Applied rewrites67.2%
Final simplification75.4%
(FPCore (x y) :precision binary64 (if (<= (+ (/ (fabs (- y x)) 2.0) x) 1e-283) (* 0.5 x) (* -0.5 y)))
double code(double x, double y) {
double tmp;
if (((fabs((y - x)) / 2.0) + x) <= 1e-283) {
tmp = 0.5 * x;
} else {
tmp = -0.5 * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((abs((y - x)) / 2.0d0) + x) <= 1d-283) then
tmp = 0.5d0 * x
else
tmp = (-0.5d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((Math.abs((y - x)) / 2.0) + x) <= 1e-283) {
tmp = 0.5 * x;
} else {
tmp = -0.5 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((math.fabs((y - x)) / 2.0) + x) <= 1e-283: tmp = 0.5 * x else: tmp = -0.5 * y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(abs(Float64(y - x)) / 2.0) + x) <= 1e-283) tmp = Float64(0.5 * x); else tmp = Float64(-0.5 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((abs((y - x)) / 2.0) + x) <= 1e-283) tmp = 0.5 * x; else tmp = -0.5 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] + x), $MachinePrecision], 1e-283], N[(0.5 * x), $MachinePrecision], N[(-0.5 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left|y - x\right|}{2} + x \leq 10^{-283}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot y\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 9.99999999999999947e-284Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f641.2
Applied rewrites1.2%
Applied rewrites98.1%
Taylor expanded in y around 0
Applied rewrites98.2%
if 9.99999999999999947e-284 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.8%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Applied rewrites67.1%
Taylor expanded in y around inf
lower-*.f6433.9
Applied rewrites33.9%
Final simplification50.5%
(FPCore (x y) :precision binary64 (if (<= x -5.8e-91) (* -0.5 (- y x)) (if (<= x 1.2e-19) (fma (fabs (- y)) 0.5 x) (fma 1.5 x (* -0.5 y)))))
double code(double x, double y) {
double tmp;
if (x <= -5.8e-91) {
tmp = -0.5 * (y - x);
} else if (x <= 1.2e-19) {
tmp = fma(fabs(-y), 0.5, x);
} else {
tmp = fma(1.5, x, (-0.5 * y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -5.8e-91) tmp = Float64(-0.5 * Float64(y - x)); elseif (x <= 1.2e-19) tmp = fma(abs(Float64(-y)), 0.5, x); else tmp = fma(1.5, x, Float64(-0.5 * y)); end return tmp end
code[x_, y_] := If[LessEqual[x, -5.8e-91], N[(-0.5 * N[(y - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.2e-19], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(1.5 * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-91}:\\
\;\;\;\;-0.5 \cdot \left(y - x\right)\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1.5, x, -0.5 \cdot y\right)\\
\end{array}
\end{array}
if x < -5.8000000000000001e-91Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6431.0
Applied rewrites31.0%
Applied rewrites87.3%
if -5.8000000000000001e-91 < x < 1.20000000000000011e-19Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
if 1.20000000000000011e-19 < x Initial program 99.6%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
Applied rewrites93.3%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6493.8
Applied rewrites93.8%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (<= x -5.8e-91) (* -0.5 (- y x)) (if (<= x 1.2e-19) (fma (fabs (- y)) 0.5 x) (fma (- y x) -0.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -5.8e-91) {
tmp = -0.5 * (y - x);
} else if (x <= 1.2e-19) {
tmp = fma(fabs(-y), 0.5, x);
} else {
tmp = fma((y - x), -0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -5.8e-91) tmp = Float64(-0.5 * Float64(y - x)); elseif (x <= 1.2e-19) tmp = fma(abs(Float64(-y)), 0.5, x); else tmp = fma(Float64(y - x), -0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, -5.8e-91], N[(-0.5 * N[(y - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.2e-19], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-91}:\\
\;\;\;\;-0.5 \cdot \left(y - x\right)\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\end{array}
\end{array}
if x < -5.8000000000000001e-91Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6431.0
Applied rewrites31.0%
Applied rewrites87.3%
if -5.8000000000000001e-91 < x < 1.20000000000000011e-19Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
if 1.20000000000000011e-19 < x Initial program 99.6%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
Applied rewrites93.3%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (<= x -5.8e-91) (* -0.5 (- y x)) (if (<= x 1.2e-19) (* (fabs (- y x)) 0.5) (fma (- y x) -0.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -5.8e-91) {
tmp = -0.5 * (y - x);
} else if (x <= 1.2e-19) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = fma((y - x), -0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -5.8e-91) tmp = Float64(-0.5 * Float64(y - x)); elseif (x <= 1.2e-19) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = fma(Float64(y - x), -0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, -5.8e-91], N[(-0.5 * N[(y - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.2e-19], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-91}:\\
\;\;\;\;-0.5 \cdot \left(y - x\right)\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-19}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\end{array}
\end{array}
if x < -5.8000000000000001e-91Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6431.0
Applied rewrites31.0%
Applied rewrites87.3%
if -5.8000000000000001e-91 < x < 1.20000000000000011e-19Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6485.6
Applied rewrites85.6%
if 1.20000000000000011e-19 < x Initial program 99.6%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
Applied rewrites93.3%
Final simplification88.1%
(FPCore (x y) :precision binary64 (if (<= x -4.4e-144) (* 0.5 x) (if (<= x 2.15e-132) (* -0.5 y) (* 1.5 x))))
double code(double x, double y) {
double tmp;
if (x <= -4.4e-144) {
tmp = 0.5 * x;
} else if (x <= 2.15e-132) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.4d-144)) then
tmp = 0.5d0 * x
else if (x <= 2.15d-132) then
tmp = (-0.5d0) * y
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.4e-144) {
tmp = 0.5 * x;
} else if (x <= 2.15e-132) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.4e-144: tmp = 0.5 * x elif x <= 2.15e-132: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4.4e-144) tmp = Float64(0.5 * x); elseif (x <= 2.15e-132) tmp = Float64(-0.5 * y); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.4e-144) tmp = 0.5 * x; elseif (x <= 2.15e-132) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.4e-144], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 2.15e-132], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{-144}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{-132}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < -4.40000000000000012e-144Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6435.4
Applied rewrites35.4%
Applied rewrites81.3%
Taylor expanded in y around 0
Applied rewrites64.9%
if -4.40000000000000012e-144 < x < 2.1499999999999998e-132Initial program 100.0%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Applied rewrites57.5%
Taylor expanded in y around inf
lower-*.f6453.2
Applied rewrites53.2%
if 2.1499999999999998e-132 < x Initial program 99.7%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.7
Applied rewrites99.7%
Applied rewrites81.5%
Taylor expanded in y around 0
distribute-rgt1-inN/A
metadata-evalN/A
lower-*.f6472.5
Applied rewrites72.5%
(FPCore (x y) :precision binary64 (if (<= x 2.15e-132) (* -0.5 (- y x)) (* 1.5 x)))
double code(double x, double y) {
double tmp;
if (x <= 2.15e-132) {
tmp = -0.5 * (y - x);
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 2.15d-132) then
tmp = (-0.5d0) * (y - x)
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2.15e-132) {
tmp = -0.5 * (y - x);
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.15e-132: tmp = -0.5 * (y - x) else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= 2.15e-132) tmp = Float64(-0.5 * Float64(y - x)); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.15e-132) tmp = -0.5 * (y - x); else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.15e-132], N[(-0.5 * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.15 \cdot 10^{-132}:\\
\;\;\;\;-0.5 \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < 2.1499999999999998e-132Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6459.4
Applied rewrites59.4%
Applied rewrites70.8%
if 2.1499999999999998e-132 < x Initial program 99.7%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.7
Applied rewrites99.7%
Applied rewrites81.5%
Taylor expanded in y around 0
distribute-rgt1-inN/A
metadata-evalN/A
lower-*.f6472.5
Applied rewrites72.5%
Final simplification71.4%
(FPCore (x y) :precision binary64 (fma (fabs (- y x)) 0.5 x))
double code(double x, double y) {
return fma(fabs((y - x)), 0.5, x);
}
function code(x, y) return fma(abs(Float64(y - x)), 0.5, x) end
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (* 0.5 x))
double code(double x, double y) {
return 0.5 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * x
end function
public static double code(double x, double y) {
return 0.5 * x;
}
def code(x, y): return 0.5 * x
function code(x, y) return Float64(0.5 * x) end
function tmp = code(x, y) tmp = 0.5 * x; end
code[x_, y_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6452.8
Applied rewrites52.8%
Applied rewrites54.1%
Taylor expanded in y around 0
Applied rewrites31.3%
herbie shell --seed 2024244
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))