
(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 9 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--N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (* y -2.0)))) (if (<= y -14200000.0) t_0 (if (<= y 5.5e+96) (* x (* x 2.0)) t_0))))
double code(double x, double y) {
double t_0 = x * (y * -2.0);
double tmp;
if (y <= -14200000.0) {
tmp = t_0;
} else if (y <= 5.5e+96) {
tmp = x * (x * 2.0);
} 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 * (y * (-2.0d0))
if (y <= (-14200000.0d0)) then
tmp = t_0
else if (y <= 5.5d+96) then
tmp = x * (x * 2.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y * -2.0);
double tmp;
if (y <= -14200000.0) {
tmp = t_0;
} else if (y <= 5.5e+96) {
tmp = x * (x * 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y * -2.0) tmp = 0 if y <= -14200000.0: tmp = t_0 elif y <= 5.5e+96: tmp = x * (x * 2.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y * -2.0)) tmp = 0.0 if (y <= -14200000.0) tmp = t_0; elseif (y <= 5.5e+96) tmp = Float64(x * Float64(x * 2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y * -2.0); tmp = 0.0; if (y <= -14200000.0) tmp = t_0; elseif (y <= 5.5e+96) tmp = x * (x * 2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -14200000.0], t$95$0, If[LessEqual[y, 5.5e+96], N[(x * N[(x * 2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y \cdot -2\right)\\
\mathbf{if}\;y \leq -14200000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+96}:\\
\;\;\;\;x \cdot \left(x \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.42e7 or 5.5000000000000002e96 < y Initial program 87.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6486.6
Simplified86.6%
if -1.42e7 < y < 5.5000000000000002e96Initial program 99.3%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6485.7
Simplified85.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (- x)))) (if (<= y -8.5e+208) t_0 (if (<= y 4.2e+152) (* x (* x 2.0)) t_0))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -8.5e+208) {
tmp = t_0;
} else if (y <= 4.2e+152) {
tmp = x * (x * 2.0);
} 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 = y * -x
if (y <= (-8.5d+208)) then
tmp = t_0
else if (y <= 4.2d+152) then
tmp = x * (x * 2.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -8.5e+208) {
tmp = t_0;
} else if (y <= 4.2e+152) {
tmp = x * (x * 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * -x tmp = 0 if y <= -8.5e+208: tmp = t_0 elif y <= 4.2e+152: tmp = x * (x * 2.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -8.5e+208) tmp = t_0; elseif (y <= 4.2e+152) tmp = Float64(x * Float64(x * 2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * -x; tmp = 0.0; if (y <= -8.5e+208) tmp = t_0; elseif (y <= 4.2e+152) tmp = x * (x * 2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -8.5e+208], t$95$0, If[LessEqual[y, 4.2e+152], N[(x * N[(x * 2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+208}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+152}:\\
\;\;\;\;x \cdot \left(x \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.4999999999999992e208 or 4.2000000000000003e152 < y Initial program 86.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6494.7
Simplified94.7%
Taylor expanded in y around -inf
mul-1-negN/A
lower-neg.f6442.0
Simplified42.0%
if -8.4999999999999992e208 < y < 4.2000000000000003e152Initial program 97.0%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6472.5
Simplified72.5%
Final simplification65.7%
(FPCore (x y) :precision binary64 (if (<= x -1.35e-142) (* x -2.0) (* x 2.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.35e-142) {
tmp = x * -2.0;
} else {
tmp = x * 2.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.35d-142)) then
tmp = x * (-2.0d0)
else
tmp = x * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.35e-142) {
tmp = x * -2.0;
} else {
tmp = x * 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.35e-142: tmp = x * -2.0 else: tmp = x * 2.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.35e-142) tmp = Float64(x * -2.0); else tmp = Float64(x * 2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.35e-142) tmp = x * -2.0; else tmp = x * 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.35e-142], N[(x * -2.0), $MachinePrecision], N[(x * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-142}:\\
\;\;\;\;x \cdot -2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 2\\
\end{array}
\end{array}
if x < -1.3499999999999999e-142Initial program 92.9%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6436.6
Simplified36.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f646.3
Simplified6.3%
if -1.3499999999999999e-142 < x Initial program 95.5%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.2
Simplified53.2%
Taylor expanded in x around 0
lower-*.f646.0
Simplified6.0%
Final simplification6.1%
(FPCore (x y) :precision binary64 (if (<= x -1.35e-142) (- x) (* x 2.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.35e-142) {
tmp = -x;
} else {
tmp = x * 2.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.35d-142)) then
tmp = -x
else
tmp = x * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.35e-142) {
tmp = -x;
} else {
tmp = x * 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.35e-142: tmp = -x else: tmp = x * 2.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.35e-142) tmp = Float64(-x); else tmp = Float64(x * 2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.35e-142) tmp = -x; else tmp = x * 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.35e-142], (-x), N[(x * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-142}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 2\\
\end{array}
\end{array}
if x < -1.3499999999999999e-142Initial program 92.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.8
Simplified71.8%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f646.3
Simplified6.3%
if -1.3499999999999999e-142 < x Initial program 95.5%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.2
Simplified53.2%
Taylor expanded in x around 0
lower-*.f646.0
Simplified6.0%
Final simplification6.1%
(FPCore (x y) :precision binary64 (if (<= x -1.35e-142) (- x) x))
double code(double x, double y) {
double tmp;
if (x <= -1.35e-142) {
tmp = -x;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.35d-142)) then
tmp = -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.35e-142) {
tmp = -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.35e-142: tmp = -x else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.35e-142) tmp = Float64(-x); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.35e-142) tmp = -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.35e-142], (-x), x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-142}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.3499999999999999e-142Initial program 92.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.8
Simplified71.8%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f646.3
Simplified6.3%
if -1.3499999999999999e-142 < x Initial program 95.5%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.2
Simplified53.2%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f643.3
Simplified3.3%
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
metadata-evalN/A
+-lft-identityN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
+-lft-identityN/A
metadata-evalN/A
flip3-+N/A
+-lft-identity6.0
Applied egg-rr6.0%
(FPCore (x y) :precision binary64 (* y (- x)))
double code(double x, double y) {
return y * -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * -x
end function
public static double code(double x, double y) {
return y * -x;
}
def code(x, y): return y * -x
function code(x, y) return Float64(y * Float64(-x)) end
function tmp = code(x, y) tmp = y * -x; end
code[x_, y_] := N[(y * (-x)), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(-x\right)
\end{array}
Initial program 94.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.5
Simplified53.5%
Taylor expanded in y around -inf
mul-1-negN/A
lower-neg.f6425.2
Simplified25.2%
Final simplification25.2%
(FPCore (x y) :precision binary64 (* x y))
double code(double x, double y) {
return x * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * y
end function
public static double code(double x, double y) {
return x * y;
}
def code(x, y): return x * y
function code(x, y) return Float64(x * y) end
function tmp = code(x, y) tmp = x * y; end
code[x_, y_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 94.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.5
Simplified53.5%
Taylor expanded in y around -inf
mul-1-negN/A
lower-neg.f6425.2
Simplified25.2%
distribute-rgt-neg-outN/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
distribute-rgt-neg-outN/A
lift-neg.f64N/A
unpow-prod-downN/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
unpow-prod-downN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
Applied egg-rr13.2%
Final simplification13.2%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 94.5%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6460.4
Simplified60.4%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f644.4
Simplified4.4%
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
metadata-evalN/A
+-lft-identityN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
+-lft-identityN/A
metadata-evalN/A
flip3-+N/A
+-lft-identity4.3
Applied egg-rr4.3%
(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 2024214
(FPCore (x y)
:name "Linear.Matrix:fromQuaternion from linear-1.19.1.3, A"
:precision binary64
:alt
(! :herbie-platform default (* (* x 2) (- x y)))
(* 2.0 (- (* x x) (* x y))))