
(FPCore (x y) :precision binary64 (* (* (* x 3.0) x) y))
double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 3.0d0) * x) * y
end function
public static double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
def code(x, y): return ((x * 3.0) * x) * y
function code(x, y) return Float64(Float64(Float64(x * 3.0) * x) * y) end
function tmp = code(x, y) tmp = ((x * 3.0) * x) * y; end
code[x_, y_] := N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 3\right) \cdot x\right) \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* (* x 3.0) x) y))
double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 3.0d0) * x) * y
end function
public static double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
def code(x, y): return ((x * 3.0) * x) * y
function code(x, y) return Float64(Float64(Float64(x * 3.0) * x) * y) end
function tmp = code(x, y) tmp = ((x * 3.0) * x) * y; end
code[x_, y_] := N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 3\right) \cdot x\right) \cdot y
\end{array}
(FPCore (x y) :precision binary64 (* (* x 3.0) (* x y)))
double code(double x, double y) {
return (x * 3.0) * (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 3.0d0) * (x * y)
end function
public static double code(double x, double y) {
return (x * 3.0) * (x * y);
}
def code(x, y): return (x * 3.0) * (x * y)
function code(x, y) return Float64(Float64(x * 3.0) * Float64(x * y)) end
function tmp = code(x, y) tmp = (x * 3.0) * (x * y); end
code[x_, y_] := N[(N[(x * 3.0), $MachinePrecision] * N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot \left(x \cdot y\right)
\end{array}
Initial program 89.5%
associate-*l*99.8%
Simplified99.8%
(FPCore (x y) :precision binary64 (* x (* x (* 3.0 y))))
double code(double x, double y) {
return x * (x * (3.0 * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (x * (3.0d0 * y))
end function
public static double code(double x, double y) {
return x * (x * (3.0 * y));
}
def code(x, y): return x * (x * (3.0 * y))
function code(x, y) return Float64(x * Float64(x * Float64(3.0 * y))) end
function tmp = code(x, y) tmp = x * (x * (3.0 * y)); end
code[x_, y_] := N[(x * N[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 \cdot y\right)\right)
\end{array}
Initial program 89.5%
*-commutative89.5%
associate-*l*99.7%
associate-*r*99.7%
Simplified99.7%
(FPCore (x y) :precision binary64 (* x (* 3.0 (* x y))))
double code(double x, double y) {
return x * (3.0 * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (3.0d0 * (x * y))
end function
public static double code(double x, double y) {
return x * (3.0 * (x * y));
}
def code(x, y): return x * (3.0 * (x * y))
function code(x, y) return Float64(x * Float64(3.0 * Float64(x * y))) end
function tmp = code(x, y) tmp = x * (3.0 * (x * y)); end
code[x_, y_] := N[(x * N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(3 \cdot \left(x \cdot y\right)\right)
\end{array}
Initial program 89.5%
associate-*l*99.8%
associate-*l*99.7%
Simplified99.7%
(FPCore (x y) :precision binary64 (* 3.0 (* x (* x y))))
double code(double x, double y) {
return 3.0 * (x * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * (x * (x * y))
end function
public static double code(double x, double y) {
return 3.0 * (x * (x * y));
}
def code(x, y): return 3.0 * (x * (x * y))
function code(x, y) return Float64(3.0 * Float64(x * Float64(x * y))) end
function tmp = code(x, y) tmp = 3.0 * (x * (x * y)); end
code[x_, y_] := N[(3.0 * N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot \left(x \cdot y\right)\right)
\end{array}
Initial program 89.5%
associate-*l*99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 89.5%
add-sqr-sqrt61.7%
pow261.7%
sqrt-prod50.3%
sqrt-pow156.7%
metadata-eval56.7%
pow156.7%
Applied egg-rr56.7%
unpow256.7%
*-commutative56.7%
associate-*r*56.8%
associate-*r*56.7%
add-sqr-sqrt99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (* 3.0 (* y (* x x))))
double code(double x, double y) {
return 3.0 * (y * (x * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * (y * (x * x))
end function
public static double code(double x, double y) {
return 3.0 * (y * (x * x));
}
def code(x, y): return 3.0 * (y * (x * x))
function code(x, y) return Float64(3.0 * Float64(y * Float64(x * x))) end
function tmp = code(x, y) tmp = 3.0 * (y * (x * x)); end
code[x_, y_] := N[(3.0 * N[(y * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(y \cdot \left(x \cdot x\right)\right)
\end{array}
Initial program 89.5%
associate-*l*99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 89.5%
unpow289.5%
Applied egg-rr89.5%
Final simplification89.5%
(FPCore (x y) :precision binary64 (* (* x 3.0) (* x y)))
double code(double x, double y) {
return (x * 3.0) * (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 3.0d0) * (x * y)
end function
public static double code(double x, double y) {
return (x * 3.0) * (x * y);
}
def code(x, y): return (x * 3.0) * (x * y)
function code(x, y) return Float64(Float64(x * 3.0) * Float64(x * y)) end
function tmp = code(x, y) tmp = (x * 3.0) * (x * y); end
code[x_, y_] := N[(N[(x * 3.0), $MachinePrecision] * N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot \left(x \cdot y\right)
\end{array}
herbie shell --seed 2024143
(FPCore (x y)
:name "Diagrams.Segment:$catParam from diagrams-lib-1.3.0.3, A"
:precision binary64
:alt
(! :herbie-platform default (* (* x 3) (* x y)))
(* (* (* x 3.0) x) y))