
(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 (<= y 2.6e-14) (* x (- x y)) (* y (- x y))))
double code(double x, double y) {
double tmp;
if (y <= 2.6e-14) {
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 <= 2.6d-14) 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 <= 2.6e-14) {
tmp = x * (x - y);
} else {
tmp = y * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.6e-14: tmp = x * (x - y) else: tmp = y * (x - y) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.6e-14) 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 <= 2.6e-14) tmp = x * (x - y); else tmp = y * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.6e-14], N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \left(x - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - y\right)\\
\end{array}
\end{array}
if y < 2.59999999999999997e-14Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 64.2%
if 2.59999999999999997e-14 < y Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 83.1%
Final simplification69.3%
(FPCore (x y) :precision binary64 (if (<= x 3.3e-25) (* y (- y)) (* x (- x y))))
double code(double x, double y) {
double tmp;
if (x <= 3.3e-25) {
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 <= 3.3d-25) 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 <= 3.3e-25) {
tmp = y * -y;
} else {
tmp = x * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.3e-25: tmp = y * -y else: tmp = x * (x - y) return tmp
function code(x, y) tmp = 0.0 if (x <= 3.3e-25) 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 <= 3.3e-25) tmp = y * -y; else tmp = x * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.3e-25], N[(y * (-y)), $MachinePrecision], N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.3 \cdot 10^{-25}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x - y\right)\\
\end{array}
\end{array}
if x < 3.2999999999999998e-25Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 67.2%
Taylor expanded in x around 0 64.7%
neg-mul-164.7%
Simplified64.7%
if 3.2999999999999998e-25 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 81.0%
Final simplification68.6%
(FPCore (x y) :precision binary64 (if (<= x 8.5e+214) (* y (- y)) (* x y)))
double code(double x, double y) {
double tmp;
if (x <= 8.5e+214) {
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 <= 8.5d+214) 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 <= 8.5e+214) {
tmp = y * -y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 8.5e+214: tmp = y * -y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= 8.5e+214) 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 <= 8.5e+214) tmp = y * -y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 8.5e+214], N[(y * (-y)), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.5 \cdot 10^{+214}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 8.50000000000000045e214Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 60.6%
Taylor expanded in x around 0 58.6%
neg-mul-158.6%
Simplified58.6%
if 8.50000000000000045e214 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 29.0%
Taylor expanded in x around inf 29.0%
Final simplification57.3%
(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 0 59.3%
Taylor expanded in x around inf 14.2%
herbie shell --seed 2024111
(FPCore (x y)
:name "Examples.Basics.BasicTests:f1 from sbv-4.4"
:precision binary64
(* (+ x y) (- x y)))