
(FPCore (x) :precision binary64 (* (* x x) x))
double code(double x) {
return (x * x) * x;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x * x) * x
end function
public static double code(double x) {
return (x * x) * x;
}
def code(x): return (x * x) * x
function code(x) return Float64(Float64(x * x) * x) end
function tmp = code(x) tmp = (x * x) * x; end
code[x_] := N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]
\left(x \cdot x\right) \cdot x
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (* x x) x))
double code(double x) {
return (x * x) * x;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x * x) * x
end function
public static double code(double x) {
return (x * x) * x;
}
def code(x): return (x * x) * x
function code(x) return Float64(Float64(x * x) * x) end
function tmp = code(x) tmp = (x * x) * x; end
code[x_] := N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]
\left(x \cdot x\right) \cdot x
(FPCore (x) :precision binary64 (pow x 3.0))
double code(double x) {
return pow(x, 3.0);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = x ** 3.0d0
end function
public static double code(double x) {
return Math.pow(x, 3.0);
}
def code(x): return math.pow(x, 3.0)
function code(x) return x ^ 3.0 end
function tmp = code(x) tmp = x ^ 3.0; end
code[x_] := N[Power[x, 3.0], $MachinePrecision]
{x}^{3}
Initial program 99.9%
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
lower-pow.f64100.0%
Applied rewrites100.0%
(FPCore (x) :precision binary64 (pow x 3.0))
double code(double x) {
return pow(x, 3.0);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = x ** 3.0d0
end function
public static double code(double x) {
return Math.pow(x, 3.0);
}
def code(x): return math.pow(x, 3.0)
function code(x) return x ^ 3.0 end
function tmp = code(x) tmp = x ^ 3.0; end
code[x_] := N[Power[x, 3.0], $MachinePrecision]
{x}^{3}
herbie shell --seed 2025313 -o setup:search
(FPCore (x)
:name "math.cube on real"
:precision binary64
:alt
(! :herbie-platform c (pow x 3))
(* (* x x) x))