
(FPCore (a x y) :precision binary64 (/ (- 1.0 (* a x)) (- x y)))
double code(double a, double x, double y) {
return (1.0 - (a * x)) / (x - y);
}
real(8) function code(a, x, y)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - (a * x)) / (x - y)
end function
public static double code(double a, double x, double y) {
return (1.0 - (a * x)) / (x - y);
}
def code(a, x, y): return (1.0 - (a * x)) / (x - y)
function code(a, x, y) return Float64(Float64(1.0 - Float64(a * x)) / Float64(x - y)) end
function tmp = code(a, x, y) tmp = (1.0 - (a * x)) / (x - y); end
code[a_, x_, y_] := N[(N[(1.0 - N[(a * x), $MachinePrecision]), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\frac{1 - a \cdot x}{x - y}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a x y) :precision binary64 (/ (- 1.0 (* a x)) (- x y)))
double code(double a, double x, double y) {
return (1.0 - (a * x)) / (x - y);
}
real(8) function code(a, x, y)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - (a * x)) / (x - y)
end function
public static double code(double a, double x, double y) {
return (1.0 - (a * x)) / (x - y);
}
def code(a, x, y): return (1.0 - (a * x)) / (x - y)
function code(a, x, y) return Float64(Float64(1.0 - Float64(a * x)) / Float64(x - y)) end
function tmp = code(a, x, y) tmp = (1.0 - (a * x)) / (x - y); end
code[a_, x_, y_] := N[(N[(1.0 - N[(a * x), $MachinePrecision]), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\frac{1 - a \cdot x}{x - y}
(FPCore (a x y) :precision binary64 (/ (fma x a -1.0) (- y x)))
double code(double a, double x, double y) {
return fma(x, a, -1.0) / (y - x);
}
function code(a, x, y) return Float64(fma(x, a, -1.0) / Float64(y - x)) end
code[a_, x_, y_] := N[(N[(x * a + -1.0), $MachinePrecision] / N[(y - x), $MachinePrecision]), $MachinePrecision]
\frac{\mathsf{fma}\left(x, a, -1\right)}{y - x}
Initial program 100.0%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-neg-inN/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
remove-double-negN/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f64100.0%
Applied rewrites100.0%
(FPCore (a x y) :precision binary64 (/ 1.0 (- x y)))
double code(double a, double x, double y) {
return 1.0 / (x - y);
}
real(8) function code(a, x, y)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / (x - y)
end function
public static double code(double a, double x, double y) {
return 1.0 / (x - y);
}
def code(a, x, y): return 1.0 / (x - y)
function code(a, x, y) return Float64(1.0 / Float64(x - y)) end
function tmp = code(a, x, y) tmp = 1.0 / (x - y); end
code[a_, x_, y_] := N[(1.0 / N[(x - y), $MachinePrecision]), $MachinePrecision]
\frac{1}{x - y}
Initial program 100.0%
Taylor expanded in a around 0
Applied rewrites99.8%
(FPCore (a x y) :precision binary64 (/ -1.0 y))
double code(double a, double x, double y) {
return -1.0 / y;
}
real(8) function code(a, x, y)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-1.0d0) / y
end function
public static double code(double a, double x, double y) {
return -1.0 / y;
}
def code(a, x, y): return -1.0 / y
function code(a, x, y) return Float64(-1.0 / y) end
function tmp = code(a, x, y) tmp = -1.0 / y; end
code[a_, x_, y_] := N[(-1.0 / y), $MachinePrecision]
\frac{-1}{y}
Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6497.9%
Applied rewrites97.9%
(FPCore (a x y) :precision binary64 (- a))
double code(double a, double x, double y) {
return -a;
}
real(8) function code(a, x, y)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -a
end function
public static double code(double a, double x, double y) {
return -a;
}
def code(a, x, y): return -a
function code(a, x, y) return Float64(-a) end
function tmp = code(a, x, y) tmp = -a; end
code[a_, x_, y_] := (-a)
-a
Initial program 100.0%
Taylor expanded in x around inf
lower-*.f642.3%
Applied rewrites2.3%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f642.3%
Applied rewrites2.3%
herbie shell --seed 1
(FPCore (a x y)
:name "(1 - a * x) / (x - y)"
:precision binary64
:pre (and (and (and (<= 0.0 a) (<= a 1.0)) (and (<= 0.0 x) (<= x 1000000000.0))) (and (<= -1000000000.0 y) (<= y -1000000000.0)))
(/ (- 1.0 (* a x)) (- x y)))