
(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 3 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
(let* ((t_0 (- (* y y))))
(if (<= x 2.5e-36)
t_0
(if (<= x 3.9e+30) (* x x) (if (<= x 4.7e+83) t_0 (* x x))))))
double code(double x, double y) {
double t_0 = -(y * y);
double tmp;
if (x <= 2.5e-36) {
tmp = t_0;
} else if (x <= 3.9e+30) {
tmp = x * x;
} else if (x <= 4.7e+83) {
tmp = t_0;
} else {
tmp = x * x;
}
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 * y)
if (x <= 2.5d-36) then
tmp = t_0
else if (x <= 3.9d+30) then
tmp = x * x
else if (x <= 4.7d+83) then
tmp = t_0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -(y * y);
double tmp;
if (x <= 2.5e-36) {
tmp = t_0;
} else if (x <= 3.9e+30) {
tmp = x * x;
} else if (x <= 4.7e+83) {
tmp = t_0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): t_0 = -(y * y) tmp = 0 if x <= 2.5e-36: tmp = t_0 elif x <= 3.9e+30: tmp = x * x elif x <= 4.7e+83: tmp = t_0 else: tmp = x * x return tmp
function code(x, y) t_0 = Float64(-Float64(y * y)) tmp = 0.0 if (x <= 2.5e-36) tmp = t_0; elseif (x <= 3.9e+30) tmp = Float64(x * x); elseif (x <= 4.7e+83) tmp = t_0; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) t_0 = -(y * y); tmp = 0.0; if (x <= 2.5e-36) tmp = t_0; elseif (x <= 3.9e+30) tmp = x * x; elseif (x <= 4.7e+83) tmp = t_0; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = (-N[(y * y), $MachinePrecision])}, If[LessEqual[x, 2.5e-36], t$95$0, If[LessEqual[x, 3.9e+30], N[(x * x), $MachinePrecision], If[LessEqual[x, 4.7e+83], t$95$0, N[(x * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot y\\
\mathbf{if}\;x \leq 2.5 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+30}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 2.50000000000000002e-36 or 3.90000000000000011e30 < x < 4.6999999999999999e83Initial program 100.0%
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
if 2.50000000000000002e-36 < x < 3.90000000000000011e30 or 4.6999999999999999e83 < x Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
(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%
Taylor expanded in x around inf 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y)
:name "Examples.Basics.BasicTests:f1 from sbv-4.4"
:precision binary64
(* (+ x y) (- x y)))