
(FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
double code(double x, double y) {
return ((x * x) + y) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
def code(x, y): return ((x * x) + y) + y
function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
function tmp = code(x, y) tmp = ((x * x) + y) + y; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + y\right) + y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
double code(double x, double y) {
return ((x * x) + y) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
def code(x, y): return ((x * x) + y) + y
function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
function tmp = code(x, y) tmp = ((x * x) + y) + y; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + y\right) + y
\end{array}
(FPCore (x y) :precision binary64 (+ (* x x) (* y 2.0)))
double code(double x, double y) {
return (x * x) + (y * 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + (y * 2.0d0)
end function
public static double code(double x, double y) {
return (x * x) + (y * 2.0);
}
def code(x, y): return (x * x) + (y * 2.0)
function code(x, y) return Float64(Float64(x * x) + Float64(y * 2.0)) end
function tmp = code(x, y) tmp = (x * x) + (y * 2.0); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + y \cdot 2
\end{array}
Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= (* x x) 500000000000.0) (* y 2.0) (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 500000000000.0) {
tmp = y * 2.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) :: tmp
if ((x * x) <= 500000000000.0d0) then
tmp = y * 2.0d0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 500000000000.0) {
tmp = y * 2.0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 500000000000.0: tmp = y * 2.0 else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 500000000000.0) tmp = Float64(y * 2.0); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 500000000000.0) tmp = y * 2.0; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 500000000000.0], N[(y * 2.0), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 500000000000:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 5e11Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f6490.3%
Simplified90.3%
if 5e11 < (*.f64 x x) Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
unpow2N/A
*-lowering-*.f6489.9%
Simplified89.9%
Final simplification90.1%
(FPCore (x y) :precision binary64 (* y 2.0))
double code(double x, double y) {
return y * 2.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * 2.0d0
end function
public static double code(double x, double y) {
return y * 2.0;
}
def code(x, y): return y * 2.0
function code(x, y) return Float64(y * 2.0) end
function tmp = code(x, y) tmp = y * 2.0; end
code[x_, y_] := N[(y * 2.0), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 2
\end{array}
Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f6447.0%
Simplified47.0%
Final simplification47.0%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
unpow2N/A
*-lowering-*.f6454.5%
Simplified54.5%
pow2N/A
pow-to-expN/A
*-commutativeN/A
count-2N/A
flip-+N/A
+-inversesN/A
+-inversesN/A
+-inversesN/A
+-inversesN/A
flip-+N/A
log-prodN/A
sqr-powN/A
metadata-evalN/A
unpow1N/A
rem-exp-log3.8%
Applied egg-rr3.8%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
unpow2N/A
*-lowering-*.f6454.5%
Simplified54.5%
Applied egg-rr3.8%
(FPCore (x y) :precision binary64 (+ (+ y y) (* x x)))
double code(double x, double y) {
return (y + y) + (x * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + y) + (x * x)
end function
public static double code(double x, double y) {
return (y + y) + (x * x);
}
def code(x, y): return (y + y) + (x * x)
function code(x, y) return Float64(Float64(y + y) + Float64(x * x)) end
function tmp = code(x, y) tmp = (y + y) + (x * x); end
code[x_, y_] := N[(N[(y + y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + y\right) + x \cdot x
\end{array}
herbie shell --seed 2024138
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalTail from random-fu-0.2.6.2"
:precision binary64
:alt
(! :herbie-platform default (+ (+ y y) (* x x)))
(+ (+ (* x x) y) y))