
(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 (or (<= y 1.56e-27) (and (not (<= y 4.6e+32)) (<= y 1.12e+119))) (* x (+ x y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y <= 1.56e-27) || (!(y <= 4.6e+32) && (y <= 1.12e+119))) {
tmp = x * (x + y);
} 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 <= 1.56d-27) .or. (.not. (y <= 4.6d+32)) .and. (y <= 1.12d+119)) then
tmp = x * (x + y)
else
tmp = y * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 1.56e-27) || (!(y <= 4.6e+32) && (y <= 1.12e+119))) {
tmp = x * (x + y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.56e-27) or (not (y <= 4.6e+32) and (y <= 1.12e+119)): tmp = x * (x + y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.56e-27) || (!(y <= 4.6e+32) && (y <= 1.12e+119))) tmp = Float64(x * Float64(x + y)); else tmp = Float64(y * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 1.56e-27) || (~((y <= 4.6e+32)) && (y <= 1.12e+119))) tmp = x * (x + y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.56e-27], And[N[Not[LessEqual[y, 4.6e+32]], $MachinePrecision], LessEqual[y, 1.12e+119]]], N[(x * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.56 \cdot 10^{-27} \lor \neg \left(y \leq 4.6 \cdot 10^{+32}\right) \land y \leq 1.12 \cdot 10^{+119}:\\
\;\;\;\;x \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 1.56e-27 or 4.5999999999999999e32 < y < 1.11999999999999994e119Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 62.9%
if 1.56e-27 < y < 4.5999999999999999e32 or 1.11999999999999994e119 < y Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 90.0%
Taylor expanded in x around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification68.0%
(FPCore (x y) :precision binary64 (if (<= y 3.2e-41) (* x (+ x y)) (* y (- x y))))
double code(double x, double y) {
double tmp;
if (y <= 3.2e-41) {
tmp = x * (x + y);
} else {
tmp = y * (x - 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.2d-41) then
tmp = x * (x + y)
else
tmp = y * (x - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.2e-41) {
tmp = x * (x + y);
} else {
tmp = y * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.2e-41: tmp = x * (x + y) else: tmp = y * (x - y) return tmp
function code(x, y) tmp = 0.0 if (y <= 3.2e-41) tmp = Float64(x * Float64(x + y)); else tmp = Float64(y * Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.2e-41) tmp = x * (x + y); else tmp = y * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.2e-41], N[(x * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{-41}:\\
\;\;\;\;x \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - y\right)\\
\end{array}
\end{array}
if y < 3.20000000000000012e-41Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 63.0%
if 3.20000000000000012e-41 < y Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 80.6%
Final simplification69.1%
(FPCore (x y) :precision binary64 (if (<= x 1.7e+162) (* y (- y)) (* x y)))
double code(double x, double y) {
double tmp;
if (x <= 1.7e+162) {
tmp = y * -y;
} else {
tmp = 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 <= 1.7d+162) then
tmp = y * -y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.7e+162) {
tmp = y * -y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.7e+162: tmp = y * -y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= 1.7e+162) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.7e+162) tmp = y * -y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.7e+162], N[(y * (-y)), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7 \cdot 10^{+162}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 1.70000000000000001e162Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 64.2%
Taylor expanded in x around 0 61.6%
neg-mul-161.6%
Simplified61.6%
if 1.70000000000000001e162 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 96.7%
Taylor expanded in x around 0 32.1%
Final simplification58.1%
(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 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 54.2%
Taylor expanded in x around 0 15.8%
herbie shell --seed 2024170
(FPCore (x y)
:name "Examples.Basics.BasicTests:f1 from sbv-4.4"
:precision binary64
(* (+ x y) (- x y)))