
(FPCore (x y) :precision binary64 (* 2.0 (+ (* x x) (* x y))))
double code(double x, double y) {
return 2.0 * ((x * x) + (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * ((x * x) + (x * y))
end function
public static double code(double x, double y) {
return 2.0 * ((x * x) + (x * y));
}
def code(x, y): return 2.0 * ((x * x) + (x * y))
function code(x, y) return Float64(2.0 * Float64(Float64(x * x) + Float64(x * y))) end
function tmp = code(x, y) tmp = 2.0 * ((x * x) + (x * y)); end
code[x_, y_] := N[(2.0 * N[(N[(x * x), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot x + x \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* 2.0 (+ (* x x) (* x y))))
double code(double x, double y) {
return 2.0 * ((x * x) + (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * ((x * x) + (x * y))
end function
public static double code(double x, double y) {
return 2.0 * ((x * x) + (x * y));
}
def code(x, y): return 2.0 * ((x * x) + (x * y))
function code(x, y) return Float64(2.0 * Float64(Float64(x * x) + Float64(x * y))) end
function tmp = code(x, y) tmp = 2.0 * ((x * x) + (x * y)); end
code[x_, y_] := N[(2.0 * N[(N[(x * x), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot x + x \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (* 2.0 (* x (+ x y))))
double code(double x, double y) {
return 2.0 * (x * (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * (x * (x + y))
end function
public static double code(double x, double y) {
return 2.0 * (x * (x + y));
}
def code(x, y): return 2.0 * (x * (x + y))
function code(x, y) return Float64(2.0 * Float64(x * Float64(x + y))) end
function tmp = code(x, y) tmp = 2.0 * (x * (x + y)); end
code[x_, y_] := N[(2.0 * N[(x * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot \left(x + y\right)\right)
\end{array}
Initial program 93.3%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -2.05e-108) (not (<= x 7.2e+58))) (* 2.0 (* x x)) (* 2.0 (* x y))))
double code(double x, double y) {
double tmp;
if ((x <= -2.05e-108) || !(x <= 7.2e+58)) {
tmp = 2.0 * (x * x);
} else {
tmp = 2.0 * (x * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.05d-108)) .or. (.not. (x <= 7.2d+58))) then
tmp = 2.0d0 * (x * x)
else
tmp = 2.0d0 * (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.05e-108) || !(x <= 7.2e+58)) {
tmp = 2.0 * (x * x);
} else {
tmp = 2.0 * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.05e-108) or not (x <= 7.2e+58): tmp = 2.0 * (x * x) else: tmp = 2.0 * (x * y) return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.05e-108) || !(x <= 7.2e+58)) tmp = Float64(2.0 * Float64(x * x)); else tmp = Float64(2.0 * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.05e-108) || ~((x <= 7.2e+58))) tmp = 2.0 * (x * x); else tmp = 2.0 * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.05e-108], N[Not[LessEqual[x, 7.2e+58]], $MachinePrecision]], N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-108} \lor \neg \left(x \leq 7.2 \cdot 10^{+58}\right):\\
\;\;\;\;2 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if x < -2.05000000000000018e-108 or 7.19999999999999993e58 < x Initial program 87.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 79.0%
unpow279.0%
Simplified79.0%
if -2.05000000000000018e-108 < x < 7.19999999999999993e58Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 87.0%
Final simplification82.7%
(FPCore (x y) :precision binary64 (if (or (<= x -2.15e-112) (not (<= x 5.4e+61))) (* 2.0 (* x x)) (* y (* 2.0 x))))
double code(double x, double y) {
double tmp;
if ((x <= -2.15e-112) || !(x <= 5.4e+61)) {
tmp = 2.0 * (x * x);
} else {
tmp = y * (2.0 * 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-112)) .or. (.not. (x <= 5.4d+61))) then
tmp = 2.0d0 * (x * x)
else
tmp = y * (2.0d0 * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.15e-112) || !(x <= 5.4e+61)) {
tmp = 2.0 * (x * x);
} else {
tmp = y * (2.0 * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.15e-112) or not (x <= 5.4e+61): tmp = 2.0 * (x * x) else: tmp = y * (2.0 * x) return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.15e-112) || !(x <= 5.4e+61)) tmp = Float64(2.0 * Float64(x * x)); else tmp = Float64(y * Float64(2.0 * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.15e-112) || ~((x <= 5.4e+61))) tmp = 2.0 * (x * x); else tmp = y * (2.0 * x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.15e-112], N[Not[LessEqual[x, 5.4e+61]], $MachinePrecision]], N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(2.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-112} \lor \neg \left(x \leq 5.4 \cdot 10^{+61}\right):\\
\;\;\;\;2 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(2 \cdot x\right)\\
\end{array}
\end{array}
if x < -2.1499999999999999e-112 or 5.4000000000000004e61 < x Initial program 87.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 79.0%
unpow279.0%
Simplified79.0%
if -2.1499999999999999e-112 < x < 5.4000000000000004e61Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
associate-*r*100.0%
flip-+72.5%
associate-*r/64.3%
Applied egg-rr64.3%
Taylor expanded in x around 0 87.0%
associate-*r*87.0%
Simplified87.0%
Final simplification82.7%
(FPCore (x y) :precision binary64 (* 2.0 (* x x)))
double code(double x, double y) {
return 2.0 * (x * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * (x * x)
end function
public static double code(double x, double y) {
return 2.0 * (x * x);
}
def code(x, y): return 2.0 * (x * x)
function code(x, y) return Float64(2.0 * Float64(x * x)) end
function tmp = code(x, y) tmp = 2.0 * (x * x); end
code[x_, y_] := N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot x\right)
\end{array}
Initial program 93.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 58.0%
unpow258.0%
Simplified58.0%
Final simplification58.0%
(FPCore (x y) :precision binary64 (* (* x 2.0) (+ x y)))
double code(double x, double y) {
return (x * 2.0) * (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 2.0d0) * (x + y)
end function
public static double code(double x, double y) {
return (x * 2.0) * (x + y);
}
def code(x, y): return (x * 2.0) * (x + y)
function code(x, y) return Float64(Float64(x * 2.0) * Float64(x + y)) end
function tmp = code(x, y) tmp = (x * 2.0) * (x + y); end
code[x_, y_] := N[(N[(x * 2.0), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2\right) \cdot \left(x + y\right)
\end{array}
herbie shell --seed 2023271
(FPCore (x y)
:name "Linear.Matrix:fromQuaternion from linear-1.19.1.3, B"
:precision binary64
:herbie-target
(* (* x 2.0) (+ x y))
(* 2.0 (+ (* x x) (* x y))))