
(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 (* (* x y) (* y 3.0)))
double code(double x, double y) {
return (x * y) * (y * 3.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) * (y * 3.0d0)
end function
public static double code(double x, double y) {
return (x * y) * (y * 3.0);
}
def code(x, y): return (x * y) * (y * 3.0)
function code(x, y) return Float64(Float64(x * y) * Float64(y * 3.0)) end
function tmp = code(x, y) tmp = (x * y) * (y * 3.0); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot \left(y \cdot 3\right)
\end{array}
Initial program 99.6%
associate-*l*89.0%
associate-*l*88.5%
Simplified88.5%
associate-*r*89.0%
*-commutative89.0%
add-sqr-sqrt42.4%
pow242.4%
pow242.4%
pow-prod-down47.7%
Applied egg-rr47.7%
unpow247.7%
swap-sqr42.4%
add-sqr-sqrt89.0%
associate-*l*99.6%
*-commutative99.6%
associate-*l*99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (* 3.0 (* y (* x y))))
double code(double x, double y) {
return 3.0 * (y * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * (y * (x * y))
end function
public static double code(double x, double y) {
return 3.0 * (y * (x * y));
}
def code(x, y): return 3.0 * (y * (x * y))
function code(x, y) return Float64(3.0 * Float64(y * Float64(x * y))) end
function tmp = code(x, y) tmp = 3.0 * (y * (x * y)); end
code[x_, y_] := N[(3.0 * N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(y \cdot \left(x \cdot y\right)\right)
\end{array}
Initial program 99.6%
associate-*l*89.0%
associate-*l*88.5%
Simplified88.5%
Taylor expanded in x around 0 88.9%
add-sqr-sqrt55.3%
pow255.3%
*-commutative55.3%
sqrt-prod42.4%
sqrt-pow147.8%
metadata-eval47.8%
pow147.8%
Applied egg-rr47.8%
unpow247.8%
swap-sqr42.5%
add-sqr-sqrt88.9%
*-commutative88.9%
associate-*r*99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (* 3.0 (* x (* y y))))
double code(double x, double y) {
return 3.0 * (x * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * (x * (y * y))
end function
public static double code(double x, double y) {
return 3.0 * (x * (y * y));
}
def code(x, y): return 3.0 * (x * (y * y))
function code(x, y) return Float64(3.0 * Float64(x * Float64(y * y))) end
function tmp = code(x, y) tmp = 3.0 * (x * (y * y)); end
code[x_, y_] := N[(3.0 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot \left(y \cdot y\right)\right)
\end{array}
Initial program 99.6%
associate-*l*89.0%
associate-*l*88.5%
Simplified88.5%
Taylor expanded in x around 0 88.9%
unpow288.9%
Applied egg-rr88.9%
(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 2024181
(FPCore (x y)
:name "Diagrams.Segment:$catParam from diagrams-lib-1.3.0.3, B"
:precision binary64
:alt
(! :herbie-platform default (* (* x (* 3 y)) y))
(* (* (* x 3.0) y) y))