
(FPCore (x y) :precision binary64 (+ (+ (* x 2.0) (* x x)) (* y y)))
double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) + (x * x)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
def code(x, y): return ((x * 2.0) + (x * x)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * 2.0) + (x * x)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2 + x \cdot x\right) + y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x 2.0) (* x x)) (* y y)))
double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) + (x * x)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
def code(x, y): return ((x * 2.0) + (x * x)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * 2.0) + (x * x)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2 + x \cdot x\right) + y \cdot y
\end{array}
(FPCore (x y) :precision binary64 (fma y y (* x (+ x 2.0))))
double code(double x, double y) {
return fma(y, y, (x * (x + 2.0)));
}
function code(x, y) return fma(y, y, Float64(x * Float64(x + 2.0))) end
code[x_, y_] := N[(y * y + N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, y, x \cdot \left(x + 2\right)\right)
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -4.8e+23)
(* x x)
(if (<= x 6.8e-89)
(* y y)
(if (<= x 7.5e-23) (+ x x) (if (<= x 2.5e+35) (* y y) (* x x))))))
double code(double x, double y) {
double tmp;
if (x <= -4.8e+23) {
tmp = x * x;
} else if (x <= 6.8e-89) {
tmp = y * y;
} else if (x <= 7.5e-23) {
tmp = x + x;
} else if (x <= 2.5e+35) {
tmp = y * y;
} else {
tmp = x * 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.8d+23)) then
tmp = x * x
else if (x <= 6.8d-89) then
tmp = y * y
else if (x <= 7.5d-23) then
tmp = x + x
else if (x <= 2.5d+35) then
tmp = y * y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.8e+23) {
tmp = x * x;
} else if (x <= 6.8e-89) {
tmp = y * y;
} else if (x <= 7.5e-23) {
tmp = x + x;
} else if (x <= 2.5e+35) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.8e+23: tmp = x * x elif x <= 6.8e-89: tmp = y * y elif x <= 7.5e-23: tmp = x + x elif x <= 2.5e+35: tmp = y * y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4.8e+23) tmp = Float64(x * x); elseif (x <= 6.8e-89) tmp = Float64(y * y); elseif (x <= 7.5e-23) tmp = Float64(x + x); elseif (x <= 2.5e+35) tmp = Float64(y * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.8e+23) tmp = x * x; elseif (x <= 6.8e-89) tmp = y * y; elseif (x <= 7.5e-23) tmp = x + x; elseif (x <= 2.5e+35) tmp = y * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.8e+23], N[(x * x), $MachinePrecision], If[LessEqual[x, 6.8e-89], N[(y * y), $MachinePrecision], If[LessEqual[x, 7.5e-23], N[(x + x), $MachinePrecision], If[LessEqual[x, 2.5e+35], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+23}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{-89}:\\
\;\;\;\;y \cdot y\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-23}:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+35}:\\
\;\;\;\;y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -4.8e23 or 2.50000000000000011e35 < x Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 88.2%
Taylor expanded in x around inf 88.2%
unpow288.2%
Simplified88.2%
if -4.8e23 < x < 6.8000000000000001e-89 or 7.4999999999999998e-23 < x < 2.50000000000000011e35Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 69.1%
unpow269.1%
Simplified69.1%
if 6.8000000000000001e-89 < x < 7.4999999999999998e-23Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 78.7%
Taylor expanded in x around 0 78.7%
count-278.7%
Simplified78.7%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (<= x -5e+23) (* x x) (if (<= x 1.2e+54) (+ (* y y) (* x 2.0)) (* x x))))
double code(double x, double y) {
double tmp;
if (x <= -5e+23) {
tmp = x * x;
} else if (x <= 1.2e+54) {
tmp = (y * y) + (x * 2.0);
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5d+23)) then
tmp = x * x
else if (x <= 1.2d+54) then
tmp = (y * y) + (x * 2.0d0)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5e+23) {
tmp = x * x;
} else if (x <= 1.2e+54) {
tmp = (y * y) + (x * 2.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+23: tmp = x * x elif x <= 1.2e+54: tmp = (y * y) + (x * 2.0) else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+23) tmp = Float64(x * x); elseif (x <= 1.2e+54) tmp = Float64(Float64(y * y) + Float64(x * 2.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e+23) tmp = x * x; elseif (x <= 1.2e+54) tmp = (y * y) + (x * 2.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+23], N[(x * x), $MachinePrecision], If[LessEqual[x, 1.2e+54], N[(N[(y * y), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+23}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+54}:\\
\;\;\;\;y \cdot y + x \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -4.9999999999999999e23 or 1.19999999999999999e54 < x Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 88.9%
Taylor expanded in x around inf 88.9%
unpow288.9%
Simplified88.9%
if -4.9999999999999999e23 < x < 1.19999999999999999e54Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 95.3%
Final simplification92.3%
(FPCore (x y) :precision binary64 (if (<= (* y y) 2.45e-16) (* x (+ x 2.0)) (* y y)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2.45e-16) {
tmp = x * (x + 2.0);
} else {
tmp = y * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 2.45d-16) then
tmp = x * (x + 2.0d0)
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 2.45e-16) {
tmp = x * (x + 2.0);
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2.45e-16: tmp = x * (x + 2.0) else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2.45e-16) tmp = Float64(x * Float64(x + 2.0)); else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 2.45e-16) tmp = x * (x + 2.0); else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2.45e-16], N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2.45 \cdot 10^{-16}:\\
\;\;\;\;x \cdot \left(x + 2\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if (*.f64 y y) < 2.44999999999999987e-16Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 92.0%
if 2.44999999999999987e-16 < (*.f64 y y) Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 85.3%
unpow285.3%
Simplified85.3%
Final simplification88.5%
(FPCore (x y) :precision binary64 (+ (* x (+ x 2.0)) (* y y)))
double code(double x, double y) {
return (x * (x + 2.0)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * (x + 2.0d0)) + (y * y)
end function
public static double code(double x, double y) {
return (x * (x + 2.0)) + (y * y);
}
def code(x, y): return (x * (x + 2.0)) + (y * y)
function code(x, y) return Float64(Float64(x * Float64(x + 2.0)) + Float64(y * y)) end
function tmp = code(x, y) tmp = (x * (x + 2.0)) + (y * y); end
code[x_, y_] := N[(N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x + 2\right) + y \cdot y
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -4.8e+23) (* x x) (if (<= x 4.1e+37) (* y y) (* x x))))
double code(double x, double y) {
double tmp;
if (x <= -4.8e+23) {
tmp = x * x;
} else if (x <= 4.1e+37) {
tmp = y * y;
} else {
tmp = x * 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.8d+23)) then
tmp = x * x
else if (x <= 4.1d+37) then
tmp = y * y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.8e+23) {
tmp = x * x;
} else if (x <= 4.1e+37) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.8e+23: tmp = x * x elif x <= 4.1e+37: tmp = y * y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4.8e+23) tmp = Float64(x * x); elseif (x <= 4.1e+37) tmp = Float64(y * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.8e+23) tmp = x * x; elseif (x <= 4.1e+37) tmp = y * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.8e+23], N[(x * x), $MachinePrecision], If[LessEqual[x, 4.1e+37], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+23}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+37}:\\
\;\;\;\;y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -4.8e23 or 4.0999999999999998e37 < x Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 88.2%
Taylor expanded in x around inf 88.2%
unpow288.2%
Simplified88.2%
if -4.8e23 < x < 4.0999999999999998e37Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 66.2%
unpow266.2%
Simplified66.2%
Final simplification76.5%
(FPCore (x y) :precision binary64 (* x x))
double code(double x, double y) {
return x * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * x
end function
public static double code(double x, double y) {
return x * x;
}
def code(x, y): return x * x
function code(x, y) return Float64(x * x) end
function tmp = code(x, y) tmp = x * x; end
code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 60.2%
Taylor expanded in x around inf 44.3%
unpow244.3%
Simplified44.3%
Final simplification44.3%
(FPCore (x y) :precision binary64 (+ (* y y) (+ (* 2.0 x) (* x x))))
double code(double x, double y) {
return (y * y) + ((2.0 * x) + (x * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * y) + ((2.0d0 * x) + (x * x))
end function
public static double code(double x, double y) {
return (y * y) + ((2.0 * x) + (x * x));
}
def code(x, y): return (y * y) + ((2.0 * x) + (x * x))
function code(x, y) return Float64(Float64(y * y) + Float64(Float64(2.0 * x) + Float64(x * x))) end
function tmp = code(x, y) tmp = (y * y) + ((2.0 * x) + (x * x)); end
code[x_, y_] := N[(N[(y * y), $MachinePrecision] + N[(N[(2.0 * x), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot y + \left(2 \cdot x + x \cdot x\right)
\end{array}
herbie shell --seed 2023227
(FPCore (x y)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
:precision binary64
:herbie-target
(+ (* y y) (+ (* 2.0 x) (* x x)))
(+ (+ (* x 2.0) (* x x)) (* y y)))