
(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 4 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 1.55) (* y (- y)) (* x (+ x y))))
double code(double x, double y) {
double tmp;
if (x <= 1.55) {
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 <= 1.55d0) 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 <= 1.55) {
tmp = y * -y;
} else {
tmp = x * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.55: tmp = y * -y else: tmp = x * (x + y) return tmp
function code(x, y) tmp = 0.0 if (x <= 1.55) 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 <= 1.55) tmp = y * -y; else tmp = x * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.55], N[(y * (-y)), $MachinePrecision], N[(x * N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x + y\right)\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 65.6%
Taylor expanded in x around 0 64.5%
neg-mul-164.5%
Simplified64.5%
if 1.55000000000000004 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 83.4%
Final simplification68.9%
(FPCore (x y) :precision binary64 (if (<= x 2.35e+148) (* y (- y)) (* x y)))
double code(double x, double y) {
double tmp;
if (x <= 2.35e+148) {
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 <= 2.35d+148) 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 <= 2.35e+148) {
tmp = y * -y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.35e+148: tmp = y * -y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= 2.35e+148) 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 <= 2.35e+148) tmp = y * -y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.35e+148], N[(y * (-y)), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.35 \cdot 10^{+148}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 2.3499999999999999e148Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.1%
Taylor expanded in x around 0 61.0%
neg-mul-161.0%
Simplified61.0%
if 2.3499999999999999e148 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 93.1%
Taylor expanded in x around 0 23.6%
Final simplification56.8%
(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 53.5%
Taylor expanded in x around 0 12.7%
herbie shell --seed 2024165
(FPCore (x y)
:name "Examples.Basics.BasicTests:f1 from sbv-4.4"
:precision binary64
(* (+ x y) (- x y)))