
(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 5 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 (* (- x y) (* x 2.0)))
double code(double x, double y) {
return (x - y) * (x * 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) * (x * 2.0d0)
end function
public static double code(double x, double y) {
return (x - y) * (x * 2.0);
}
def code(x, y): return (x - y) * (x * 2.0)
function code(x, y) return Float64(Float64(x - y) * Float64(x * 2.0)) end
function tmp = code(x, y) tmp = (x - y) * (x * 2.0); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x - y\right) \cdot \left(x \cdot 2\right)
\end{array}
Initial program 94.5%
distribute-lft-out--100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -6.8e+30) (not (<= y 3.35e-18))) (* y (* x -2.0)) (* x (+ x x))))
double code(double x, double y) {
double tmp;
if ((y <= -6.8e+30) || !(y <= 3.35e-18)) {
tmp = y * (x * -2.0);
} else {
tmp = x * (x + x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-6.8d+30)) .or. (.not. (y <= 3.35d-18))) then
tmp = y * (x * (-2.0d0))
else
tmp = x * (x + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -6.8e+30) || !(y <= 3.35e-18)) {
tmp = y * (x * -2.0);
} else {
tmp = x * (x + x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.8e+30) or not (y <= 3.35e-18): tmp = y * (x * -2.0) else: tmp = x * (x + x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.8e+30) || !(y <= 3.35e-18)) tmp = Float64(y * Float64(x * -2.0)); else tmp = Float64(x * Float64(x + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.8e+30) || ~((y <= 3.35e-18))) tmp = y * (x * -2.0); else tmp = x * (x + x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.8e+30], N[Not[LessEqual[y, 3.35e-18]], $MachinePrecision]], N[(y * N[(x * -2.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+30} \lor \neg \left(y \leq 3.35 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x + x\right)\\
\end{array}
\end{array}
if y < -6.8000000000000005e30 or 3.3499999999999999e-18 < y Initial program 88.2%
Taylor expanded in x around 0 81.4%
*-commutative81.4%
associate-*r*81.4%
Simplified81.4%
if -6.8000000000000005e30 < y < 3.3499999999999999e-18Initial program 100.0%
Taylor expanded in x around inf 94.0%
unpow294.0%
count-294.0%
distribute-lft-in94.1%
Simplified94.1%
Final simplification88.2%
(FPCore (x y) :precision binary64 (if (<= x -6.7e-102) (* y y) (if (<= x 3.3e-168) 0.0 (* y y))))
double code(double x, double y) {
double tmp;
if (x <= -6.7e-102) {
tmp = y * y;
} else if (x <= 3.3e-168) {
tmp = 0.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 (x <= (-6.7d-102)) then
tmp = y * y
else if (x <= 3.3d-168) then
tmp = 0.0d0
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.7e-102) {
tmp = y * y;
} else if (x <= 3.3e-168) {
tmp = 0.0;
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.7e-102: tmp = y * y elif x <= 3.3e-168: tmp = 0.0 else: tmp = y * y return tmp
function code(x, y) tmp = 0.0 if (x <= -6.7e-102) tmp = Float64(y * y); elseif (x <= 3.3e-168) tmp = 0.0; else tmp = Float64(y * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.7e-102) tmp = y * y; elseif (x <= 3.3e-168) tmp = 0.0; else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.7e-102], N[(y * y), $MachinePrecision], If[LessEqual[x, 3.3e-168], 0.0, N[(y * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.7 \cdot 10^{-102}:\\
\;\;\;\;y \cdot y\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{-168}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if x < -6.7e-102 or 3.3000000000000001e-168 < x Initial program 92.5%
distribute-lft-out--100.0%
associate-*r*100.0%
flip--80.9%
associate-*r/67.9%
add-log-exp35.4%
*-commutative35.4%
exp-lft-sqr35.4%
log-prod35.4%
add-log-exp38.0%
add-log-exp67.9%
Applied egg-rr67.9%
associate-/l*80.8%
difference-of-squares91.4%
associate-/r*99.8%
*-inverses99.8%
Simplified99.8%
Applied egg-rr14.8%
if -6.7e-102 < x < 3.3000000000000001e-168Initial program 100.0%
distribute-lft-out--100.0%
associate-*r*100.0%
flip--73.0%
associate-*r/67.4%
add-log-exp47.1%
*-commutative47.1%
exp-lft-sqr47.1%
log-prod47.1%
add-log-exp50.9%
add-log-exp67.4%
Applied egg-rr67.4%
associate-/l*72.8%
difference-of-squares72.8%
associate-/r*99.8%
*-inverses99.8%
Simplified99.8%
Applied egg-rr48.0%
+-inverses48.0%
Simplified48.0%
Final simplification23.6%
(FPCore (x y) :precision binary64 (* x (+ x x)))
double code(double x, double y) {
return x * (x + x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (x + x)
end function
public static double code(double x, double y) {
return x * (x + x);
}
def code(x, y): return x * (x + x)
function code(x, y) return Float64(x * Float64(x + x)) end
function tmp = code(x, y) tmp = x * (x + x); end
code[x_, y_] := N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x + x\right)
\end{array}
Initial program 94.5%
Taylor expanded in x around inf 62.6%
unpow262.6%
count-262.6%
distribute-lft-in62.7%
Simplified62.7%
Final simplification62.7%
(FPCore (x y) :precision binary64 0.0)
double code(double x, double y) {
return 0.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0
end function
public static double code(double x, double y) {
return 0.0;
}
def code(x, y): return 0.0
function code(x, y) return 0.0 end
function tmp = code(x, y) tmp = 0.0; end
code[x_, y_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 94.5%
distribute-lft-out--100.0%
associate-*r*100.0%
flip--78.8%
associate-*r/67.8%
add-log-exp38.5%
*-commutative38.5%
exp-lft-sqr38.5%
log-prod38.5%
add-log-exp41.4%
add-log-exp67.8%
Applied egg-rr67.8%
associate-/l*78.7%
difference-of-squares86.5%
associate-/r*99.8%
*-inverses99.8%
Simplified99.8%
Applied egg-rr15.5%
+-inverses15.5%
Simplified15.5%
Final simplification15.5%
(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 2023187
(FPCore (x y)
:name "Linear.Matrix:fromQuaternion from linear-1.19.1.3, A"
:precision binary64
:herbie-target
(* (* x 2.0) (- x y))
(* 2.0 (- (* x x) (* x y))))