
(FPCore (x y) :precision binary64 (* (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) * (x - y)
end function
public static double code(double x, double y) {
return (x + y) * (x - y);
}
def code(x, y): return (x + y) * (x - y)
function code(x, y) return Float64(Float64(x + y) * Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) * (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(x - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) * (x - y)
end function
public static double code(double x, double y) {
return (x + y) * (x - y);
}
def code(x, y): return (x + y) * (x - y)
function code(x, y) return Float64(Float64(x + y) * Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) * (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(x - y\right)
\end{array}
(FPCore (x y) :precision binary64 (* (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) * (x - y)
end function
public static double code(double x, double y) {
return (x + y) * (x - y);
}
def code(x, y): return (x + y) * (x - y)
function code(x, y) return Float64(Float64(x + y) * Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) * (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(x - y\right)
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= x 5.1e+42) (* y (- x y)) (* x (- x y))))
double code(double x, double y) {
double tmp;
if (x <= 5.1e+42) {
tmp = y * (x - y);
} else {
tmp = x * (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 <= 5.1d+42) then
tmp = y * (x - y)
else
tmp = x * (x - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 5.1e+42) {
tmp = y * (x - y);
} else {
tmp = x * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 5.1e+42: tmp = y * (x - y) else: tmp = x * (x - y) return tmp
function code(x, y) tmp = 0.0 if (x <= 5.1e+42) tmp = Float64(y * Float64(x - y)); else tmp = Float64(x * Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 5.1e+42) tmp = y * (x - y); else tmp = x * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 5.1e+42], N[(y * N[(x - y), $MachinePrecision]), $MachinePrecision], N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.1 \cdot 10^{+42}:\\
\;\;\;\;y \cdot \left(x - y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x - y\right)\\
\end{array}
\end{array}
if x < 5.0999999999999999e42Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 67.2%
if 5.0999999999999999e42 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.9%
Final simplification72.5%
(FPCore (x y) :precision binary64 (if (<= x 1e+43) (* y (- y)) (* x (- x y))))
double code(double x, double y) {
double tmp;
if (x <= 1e+43) {
tmp = y * -y;
} else {
tmp = x * (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 <= 1d+43) then
tmp = y * -y
else
tmp = x * (x - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1e+43) {
tmp = y * -y;
} else {
tmp = x * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1e+43: tmp = y * -y else: tmp = x * (x - y) return tmp
function code(x, y) tmp = 0.0 if (x <= 1e+43) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1e+43) tmp = y * -y; else tmp = x * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1e+43], N[(y * (-y)), $MachinePrecision], N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+43}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x - y\right)\\
\end{array}
\end{array}
if x < 1.00000000000000001e43Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 67.5%
neg-mul-167.5%
Simplified67.5%
Taylor expanded in x around 0 66.3%
if 1.00000000000000001e43 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.9%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (<= y 0.051) (* x x) (* y (- y))))
double code(double x, double y) {
double tmp;
if (y <= 0.051) {
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 <= 0.051d0) 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 <= 0.051) {
tmp = x * x;
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.051: tmp = x * x else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.051) tmp = Float64(x * x); else tmp = Float64(y * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.051) tmp = x * x; else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.051], N[(x * x), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.051:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 0.0509999999999999967Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 63.0%
*-commutative63.0%
sub-neg63.0%
distribute-rgt-in61.9%
pow261.9%
add-sqr-sqrt32.3%
sqrt-unprod66.4%
sqr-neg66.4%
sqrt-unprod29.6%
add-sqr-sqrt62.0%
Applied egg-rr62.0%
unpow262.0%
distribute-rgt-in63.6%
Simplified63.6%
Taylor expanded in x around inf 61.2%
if 0.0509999999999999967 < y Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 83.7%
neg-mul-183.7%
Simplified83.7%
Taylor expanded in x around 0 80.1%
Final simplification66.0%
(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 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 54.6%
*-commutative54.6%
sub-neg54.6%
distribute-rgt-in51.4%
pow251.4%
add-sqr-sqrt24.1%
sqrt-unprod58.0%
sqr-neg58.0%
sqrt-unprod27.2%
add-sqr-sqrt51.3%
Applied egg-rr51.3%
unpow251.3%
distribute-rgt-in54.5%
Simplified54.5%
Taylor expanded in x around inf 51.0%
herbie shell --seed 2024135
(FPCore (x y)
:name "Examples.Basics.BasicTests:f1 from sbv-4.4"
:precision binary64
(* (+ x y) (- x y)))