
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\end{array}
(FPCore (x y) :precision binary64 (if (<= (+ (+ (* x x) (* (* x 2.0) y)) (* y y)) 5e+278) (fma x x (* y (+ (* x 2.0) y))) (+ (* x x) (* y y))))
double code(double x, double y) {
double tmp;
if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 5e+278) {
tmp = fma(x, x, (y * ((x * 2.0) + y)));
} else {
tmp = (x * x) + (y * y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) <= 5e+278) tmp = fma(x, x, Float64(y * Float64(Float64(x * 2.0) + y))); else tmp = Float64(Float64(x * x) + Float64(y * y)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], 5e+278], N[(x * x + N[(y * N[(N[(x * 2.0), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 5 \cdot 10^{+278}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) < 5.00000000000000029e278Initial program 100.0%
associate-+l+100.0%
fma-def100.0%
distribute-rgt-out100.0%
Simplified100.0%
if 5.00000000000000029e278 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) Initial program 86.1%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))) (if (<= t_0 5e+278) t_0 (+ (* x x) (* y y)))))
double code(double x, double y) {
double t_0 = ((x * x) + ((x * 2.0) * y)) + (y * y);
double tmp;
if (t_0 <= 5e+278) {
tmp = t_0;
} else {
tmp = (x * x) + (y * 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 = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
if (t_0 <= 5d+278) then
tmp = t_0
else
tmp = (x * x) + (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x * x) + ((x * 2.0) * y)) + (y * y);
double tmp;
if (t_0 <= 5e+278) {
tmp = t_0;
} else {
tmp = (x * x) + (y * y);
}
return tmp;
}
def code(x, y): t_0 = ((x * x) + ((x * 2.0) * y)) + (y * y) tmp = 0 if t_0 <= 5e+278: tmp = t_0 else: tmp = (x * x) + (y * y) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) tmp = 0.0 if (t_0 <= 5e+278) tmp = t_0; else tmp = Float64(Float64(x * x) + Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) t_0 = ((x * x) + ((x * 2.0) * y)) + (y * y); tmp = 0.0; if (t_0 <= 5e+278) tmp = t_0; else tmp = (x * x) + (y * y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+278], t$95$0, N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+278}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) < 5.00000000000000029e278Initial program 100.0%
if 5.00000000000000029e278 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) Initial program 86.1%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y 2e+135) (+ (* y y) (* x (+ x (* 2.0 y)))) (+ (* x x) (* y y))))
double code(double x, double y) {
double tmp;
if (y <= 2e+135) {
tmp = (y * y) + (x * (x + (2.0 * y)));
} else {
tmp = (x * x) + (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 <= 2d+135) then
tmp = (y * y) + (x * (x + (2.0d0 * y)))
else
tmp = (x * x) + (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2e+135) {
tmp = (y * y) + (x * (x + (2.0 * y)));
} else {
tmp = (x * x) + (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e+135: tmp = (y * y) + (x * (x + (2.0 * y))) else: tmp = (x * x) + (y * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 2e+135) tmp = Float64(Float64(y * y) + Float64(x * Float64(x + Float64(2.0 * y)))); else tmp = Float64(Float64(x * x) + Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e+135) tmp = (y * y) + (x * (x + (2.0 * y))); else tmp = (x * x) + (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e+135], N[(N[(y * y), $MachinePrecision] + N[(x * N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{+135}:\\
\;\;\;\;y \cdot y + x \cdot \left(x + 2 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\
\end{array}
\end{array}
if y < 1.99999999999999992e135Initial program 96.7%
associate-+l+96.7%
fma-def96.7%
distribute-rgt-out98.1%
Simplified98.1%
fma-udef98.1%
distribute-rgt-in96.7%
associate-+l+96.7%
+-commutative96.7%
associate-*l*96.7%
distribute-lft-out98.6%
Applied egg-rr98.6%
if 1.99999999999999992e135 < y Initial program 77.5%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification98.8%
(FPCore (x y) :precision binary64 (+ (* x x) (* y y)))
double code(double x, double y) {
return (x * x) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + (y * y)
end function
public static double code(double x, double y) {
return (x * x) + (y * y);
}
def code(x, y): return (x * x) + (y * y)
function code(x, y) return Float64(Float64(x * x) + Float64(y * y)) end
function tmp = code(x, y) tmp = (x * x) + (y * y); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + y \cdot y
\end{array}
Initial program 93.7%
Taylor expanded in x around inf 96.8%
unpow296.8%
Simplified96.8%
Final simplification96.8%
(FPCore (x y) :precision binary64 (if (<= y 3.8e-114) (* x x) (* y y)))
double code(double x, double y) {
double tmp;
if (y <= 3.8e-114) {
tmp = x * x;
} 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 <= 3.8d-114) then
tmp = x * x
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.8e-114) {
tmp = x * x;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.8e-114: tmp = x * x else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.8e-114) tmp = Float64(x * x); else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.8e-114) tmp = x * x; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.8e-114], N[(x * x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.8 \cdot 10^{-114}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if y < 3.7999999999999998e-114Initial program 97.0%
associate-+l+97.0%
fma-def97.0%
distribute-rgt-out98.8%
Simplified98.8%
fma-udef98.8%
distribute-rgt-in97.0%
associate-+l+97.0%
+-commutative97.0%
associate-*l*97.0%
distribute-lft-out98.2%
Applied egg-rr98.2%
Taylor expanded in y around 0 60.4%
unpow260.4%
Simplified60.4%
if 3.7999999999999998e-114 < y Initial program 87.2%
Taylor expanded in x around 0 75.1%
unpow275.1%
Simplified75.1%
Final simplification65.4%
(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 93.7%
associate-+l+93.7%
fma-def93.7%
distribute-rgt-out97.3%
Simplified97.3%
fma-udef97.2%
distribute-rgt-in93.7%
associate-+l+93.7%
+-commutative93.7%
associate-*l*93.7%
distribute-lft-out96.5%
Applied egg-rr96.5%
Taylor expanded in y around 0 54.0%
unpow254.0%
Simplified54.0%
Final simplification54.0%
(FPCore (x y) :precision binary64 (+ (* x x) (+ (* y y) (* (* x y) 2.0))))
double code(double x, double y) {
return (x * x) + ((y * y) + ((x * y) * 2.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + ((y * y) + ((x * y) * 2.0d0))
end function
public static double code(double x, double y) {
return (x * x) + ((y * y) + ((x * y) * 2.0));
}
def code(x, y): return (x * x) + ((y * y) + ((x * y) * 2.0))
function code(x, y) return Float64(Float64(x * x) + Float64(Float64(y * y) + Float64(Float64(x * y) * 2.0))) end
function tmp = code(x, y) tmp = (x * x) + ((y * y) + ((x * y) * 2.0)); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + \left(y \cdot y + \left(x \cdot y\right) \cdot 2\right)
\end{array}
herbie shell --seed 2023257
(FPCore (x y)
:name "Examples.Basics.ProofTests:f4 from sbv-4.4"
:precision binary64
:herbie-target
(+ (* x x) (+ (* y y) (* (* x y) 2.0)))
(+ (+ (* x x) (* (* x 2.0) y)) (* y y)))