
(FPCore (x y) :precision binary64 (* (* (* x 3.0) y) y))
double code(double x, double y) {
return ((x * 3.0) * y) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 3.0d0) * y) * y
end function
public static double code(double x, double y) {
return ((x * 3.0) * y) * y;
}
def code(x, y): return ((x * 3.0) * y) * y
function code(x, y) return Float64(Float64(Float64(x * 3.0) * y) * y) end
function tmp = code(x, y) tmp = ((x * 3.0) * y) * y; end
code[x_, y_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 3\right) \cdot y\right) \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* (* x 3.0) y) y))
double code(double x, double y) {
return ((x * 3.0) * y) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 3.0d0) * y) * y
end function
public static double code(double x, double y) {
return ((x * 3.0) * y) * y;
}
def code(x, y): return ((x * 3.0) * y) * y
function code(x, y) return Float64(Float64(Float64(x * 3.0) * y) * y) end
function tmp = code(x, y) tmp = ((x * 3.0) * y) * y; end
code[x_, y_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 3\right) \cdot y\right) \cdot y
\end{array}
(FPCore (x y) :precision binary64 (* y (* 3.0 (* x y))))
double code(double x, double y) {
return y * (3.0 * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (3.0d0 * (x * y))
end function
public static double code(double x, double y) {
return y * (3.0 * (x * y));
}
def code(x, y): return y * (3.0 * (x * y))
function code(x, y) return Float64(y * Float64(3.0 * Float64(x * y))) end
function tmp = code(x, y) tmp = y * (3.0 * (x * y)); end
code[x_, y_] := N[(y * N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(3 \cdot \left(x \cdot y\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (* x (* y (* 3.0 y))))
double code(double x, double y) {
return x * (y * (3.0 * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (y * (3.0d0 * y))
end function
public static double code(double x, double y) {
return x * (y * (3.0 * y));
}
def code(x, y): return x * (y * (3.0 * y))
function code(x, y) return Float64(x * Float64(y * Float64(3.0 * y))) end
function tmp = code(x, y) tmp = x * (y * (3.0 * y)); end
code[x_, y_] := N[(x * N[(y * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y \cdot \left(3 \cdot y\right)\right)
\end{array}
Initial program 99.8%
associate-*l*89.5%
associate-*l*89.5%
Simplified89.5%
add-sqr-sqrt89.3%
sqrt-unprod74.4%
pow1/274.4%
*-commutative74.4%
*-commutative74.4%
swap-sqr74.4%
pow274.4%
pow274.4%
pow-prod-up74.5%
metadata-eval74.5%
metadata-eval74.5%
Applied egg-rr74.5%
unpow1/274.5%
Simplified74.5%
*-commutative74.5%
sqrt-prod74.4%
metadata-eval74.4%
sqrt-pow189.5%
metadata-eval89.5%
pow289.5%
associate-*l*89.5%
*-commutative89.5%
Applied egg-rr89.5%
Final simplification89.5%
(FPCore (x y) :precision binary64 (* x (* 3.0 (* y y))))
double code(double x, double y) {
return x * (3.0 * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (3.0d0 * (y * y))
end function
public static double code(double x, double y) {
return x * (3.0 * (y * y));
}
def code(x, y): return x * (3.0 * (y * y))
function code(x, y) return Float64(x * Float64(3.0 * Float64(y * y))) end
function tmp = code(x, y) tmp = x * (3.0 * (y * y)); end
code[x_, y_] := N[(x * N[(3.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(3 \cdot \left(y \cdot y\right)\right)
\end{array}
Initial program 99.8%
associate-*l*89.5%
associate-*l*89.5%
Simplified89.5%
(FPCore (x y) :precision binary64 (* (* x (* 3.0 y)) y))
double code(double x, double y) {
return (x * (3.0 * y)) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * (3.0d0 * y)) * y
end function
public static double code(double x, double y) {
return (x * (3.0 * y)) * y;
}
def code(x, y): return (x * (3.0 * y)) * y
function code(x, y) return Float64(Float64(x * Float64(3.0 * y)) * y) end
function tmp = code(x, y) tmp = (x * (3.0 * y)) * y; end
code[x_, y_] := N[(N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(3 \cdot y\right)\right) \cdot y
\end{array}
herbie shell --seed 2024110
(FPCore (x y)
:name "Diagrams.Segment:$catParam from diagrams-lib-1.3.0.3, B"
:precision binary64
:alt
(* (* x (* 3.0 y)) y)
(* (* (* x 3.0) y) y))