
(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 5 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 (+ (+ (* 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}
Initial program 100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (+ 2.0 x))))
(if (<= x -33500000000000.0)
t_0
(if (<= x 7.5e+20) (+ (* 2.0 x) (* y y)) t_0))))
double code(double x, double y) {
double t_0 = x * (2.0 + x);
double tmp;
if (x <= -33500000000000.0) {
tmp = t_0;
} else if (x <= 7.5e+20) {
tmp = (2.0 * x) + (y * y);
} else {
tmp = t_0;
}
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 = x * (2.0d0 + x)
if (x <= (-33500000000000.0d0)) then
tmp = t_0
else if (x <= 7.5d+20) then
tmp = (2.0d0 * x) + (y * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (2.0 + x);
double tmp;
if (x <= -33500000000000.0) {
tmp = t_0;
} else if (x <= 7.5e+20) {
tmp = (2.0 * x) + (y * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (2.0 + x) tmp = 0 if x <= -33500000000000.0: tmp = t_0 elif x <= 7.5e+20: tmp = (2.0 * x) + (y * y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(2.0 + x)) tmp = 0.0 if (x <= -33500000000000.0) tmp = t_0; elseif (x <= 7.5e+20) tmp = Float64(Float64(2.0 * x) + Float64(y * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (2.0 + x); tmp = 0.0; if (x <= -33500000000000.0) tmp = t_0; elseif (x <= 7.5e+20) tmp = (2.0 * x) + (y * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(2.0 + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -33500000000000.0], t$95$0, If[LessEqual[x, 7.5e+20], N[(N[(2.0 * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(2 + x\right)\\
\mathbf{if}\;x \leq -33500000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+20}:\\
\;\;\;\;2 \cdot x + y \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.35e13 or 7.5e20 < x Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 83.6%
if -3.35e13 < x < 7.5e20Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 97.8%
(FPCore (x y) :precision binary64 (+ (* x (+ 2.0 x)) (* y y)))
double code(double x, double y) {
return (x * (2.0 + x)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * (2.0d0 + x)) + (y * y)
end function
public static double code(double x, double y) {
return (x * (2.0 + x)) + (y * y);
}
def code(x, y): return (x * (2.0 + x)) + (y * y)
function code(x, y) return Float64(Float64(x * Float64(2.0 + x)) + Float64(y * y)) end
function tmp = code(x, y) tmp = (x * (2.0 + x)) + (y * y); end
code[x_, y_] := N[(N[(x * N[(2.0 + x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(2 + x\right) + y \cdot y
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (* x (+ 2.0 x)))
double code(double x, double y) {
return x * (2.0 + x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (2.0d0 + x)
end function
public static double code(double x, double y) {
return x * (2.0 + x);
}
def code(x, y): return x * (2.0 + x)
function code(x, y) return Float64(x * Float64(2.0 + x)) end
function tmp = code(x, y) tmp = x * (2.0 + x); end
code[x_, y_] := N[(x * N[(2.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(2 + x\right)
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 57.0%
(FPCore (x y) :precision binary64 (* 2.0 x))
double code(double x, double y) {
return 2.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * x
end function
public static double code(double x, double y) {
return 2.0 * x;
}
def code(x, y): return 2.0 * x
function code(x, y) return Float64(2.0 * x) end
function tmp = code(x, y) tmp = 2.0 * x; end
code[x_, y_] := N[(2.0 * x), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot x
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 57.0%
Taylor expanded in x around 0 20.2%
(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 2024076 -o generate:simplify
(FPCore (x y)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
:precision binary64
:alt
(+ (* y y) (+ (* 2.0 x) (* x x)))
(+ (+ (* x 2.0) (* x x)) (* y y)))