
(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 7.5e+57) (* y (- x y)) (* x (- x y))))
double code(double x, double y) {
double tmp;
if (x <= 7.5e+57) {
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 <= 7.5d+57) 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 <= 7.5e+57) {
tmp = y * (x - y);
} else {
tmp = x * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 7.5e+57: tmp = y * (x - y) else: tmp = x * (x - y) return tmp
function code(x, y) tmp = 0.0 if (x <= 7.5e+57) 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 <= 7.5e+57) tmp = y * (x - y); else tmp = x * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 7.5e+57], N[(y * N[(x - y), $MachinePrecision]), $MachinePrecision], N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.5 \cdot 10^{+57}:\\
\;\;\;\;y \cdot \left(x - y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x - y\right)\\
\end{array}
\end{array}
if x < 7.5000000000000006e57Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 66.0%
if 7.5000000000000006e57 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 83.8%
distribute-rgt-in74.4%
fma-define74.4%
*-commutative74.4%
add-sqr-sqrt35.0%
sqrt-unprod78.8%
sqr-neg78.8%
sqrt-unprod43.8%
add-sqr-sqrt79.1%
distribute-rgt-neg-out79.1%
fma-neg74.4%
pow274.4%
Applied egg-rr74.4%
unpow274.4%
distribute-lft-out--88.4%
Simplified88.4%
Final simplification71.6%
(FPCore (x y) :precision binary64 (if (<= x 6.2e+57) (* y (- y)) (* x (- x y))))
double code(double x, double y) {
double tmp;
if (x <= 6.2e+57) {
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 <= 6.2d+57) 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 <= 6.2e+57) {
tmp = y * -y;
} else {
tmp = x * (x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 6.2e+57: tmp = y * -y else: tmp = x * (x - y) return tmp
function code(x, y) tmp = 0.0 if (x <= 6.2e+57) 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 <= 6.2e+57) tmp = y * -y; else tmp = x * (x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 6.2e+57], N[(y * (-y)), $MachinePrecision], N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.2 \cdot 10^{+57}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x - y\right)\\
\end{array}
\end{array}
if x < 6.20000000000000026e57Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 66.1%
neg-mul-166.1%
Simplified66.1%
Taylor expanded in x around 0 64.3%
if 6.20000000000000026e57 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 83.8%
distribute-rgt-in74.4%
fma-define74.4%
*-commutative74.4%
add-sqr-sqrt35.0%
sqrt-unprod78.8%
sqr-neg78.8%
sqrt-unprod43.8%
add-sqr-sqrt79.1%
distribute-rgt-neg-out79.1%
fma-neg74.4%
pow274.4%
Applied egg-rr74.4%
unpow274.4%
distribute-lft-out--88.4%
Simplified88.4%
Final simplification70.4%
(FPCore (x y) :precision binary64 (if (<= x 1.22e+67) (* y (- y)) (* x x)))
double code(double x, double y) {
double tmp;
if (x <= 1.22e+67) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.22d+67) then
tmp = y * -y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.22e+67) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.22e+67: tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.22e+67) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.22e+67) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.22e+67], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.22 \cdot 10^{+67}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.22000000000000004e67Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 66.2%
neg-mul-166.2%
Simplified66.2%
Taylor expanded in x around 0 64.5%
if 1.22000000000000004e67 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 85.1%
distribute-rgt-in75.6%
fma-define75.6%
*-commutative75.6%
add-sqr-sqrt35.6%
sqrt-unprod80.0%
sqr-neg80.0%
sqrt-unprod44.5%
add-sqr-sqrt78.7%
distribute-rgt-neg-out78.7%
fma-neg74.0%
pow274.0%
Applied egg-rr74.0%
unpow274.0%
distribute-lft-out--88.3%
Simplified88.3%
Taylor expanded in x around inf 80.5%
Final simplification68.4%
(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 59.4%
distribute-rgt-in55.1%
fma-define55.9%
*-commutative55.9%
add-sqr-sqrt26.9%
sqrt-unprod63.3%
sqr-neg63.3%
sqrt-unprod30.2%
add-sqr-sqrt57.6%
distribute-rgt-neg-out57.6%
fma-neg56.0%
pow256.0%
Applied egg-rr56.0%
unpow256.0%
distribute-lft-out--61.1%
Simplified61.1%
Taylor expanded in x around inf 56.7%
herbie shell --seed 2024145
(FPCore (x y)
:name "Examples.Basics.BasicTests:f1 from sbv-4.4"
:precision binary64
(* (+ x y) (- x y)))