(FPCore (x y z t a b) :precision binary64 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ y (+ t x))))
(+
(* a (+ (/ y t_1) (/ t t_1)))
(- (* (/ (+ y x) (+ x (+ y t))) z) (/ y (/ t_1 b))))))double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = y + (t + x);
return (a * ((y / t_1) + (t / t_1))) + ((((y + x) / (x + (y + t))) * z) - (y / (t_1 / b)));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
end function
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
t_1 = y + (t + x)
code = (a * ((y / t_1) + (t / t_1))) + ((((y + x) / (x + (y + t))) * z) - (y / (t_1 / b)))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = y + (t + x);
return (a * ((y / t_1) + (t / t_1))) + ((((y + x) / (x + (y + t))) * z) - (y / (t_1 / b)));
}
def code(x, y, z, t, a, b): return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
def code(x, y, z, t, a, b): t_1 = y + (t + x) return (a * ((y / t_1) + (t / t_1))) + ((((y + x) / (x + (y + t))) * z) - (y / (t_1 / b)))
function code(x, y, z, t, a, b) return Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) end
function code(x, y, z, t, a, b) t_1 = Float64(y + Float64(t + x)) return Float64(Float64(a * Float64(Float64(y / t_1) + Float64(t / t_1))) + Float64(Float64(Float64(Float64(y + x) / Float64(x + Float64(y + t))) * z) - Float64(y / Float64(t_1 / b)))) end
function tmp = code(x, y, z, t, a, b) tmp = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y); end
function tmp = code(x, y, z, t, a, b) t_1 = y + (t + x); tmp = (a * ((y / t_1) + (t / t_1))) + ((((y + x) / (x + (y + t))) * z) - (y / (t_1 / b))); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y + N[(t + x), $MachinePrecision]), $MachinePrecision]}, N[(N[(a * N[(N[(y / t$95$1), $MachinePrecision] + N[(t / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(y + x), $MachinePrecision] / N[(x + N[(y + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision] - N[(y / N[(t$95$1 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\begin{array}{l}
t_1 := y + \left(t + x\right)\\
a \cdot \left(\frac{y}{t_1} + \frac{t}{t_1}\right) + \left(\frac{y + x}{x + \left(y + t\right)} \cdot z - \frac{y}{\frac{t_1}{b}}\right)
\end{array}
Results
| Original | 26.8 |
|---|---|
| Target | 11.5 |
| Herbie | 1.5 |
Initial program 26.8
Taylor expanded in a around 0 19.0
Simplified19.0
Taylor expanded in z around inf 19.0
Simplified0.9
Applied egg-rr1.5
Final simplification1.5
herbie shell --seed 2022210
(FPCore (x y z t a b)
:name "AI.Clustering.Hierarchical.Internal:ward from clustering-0.2.1"
:precision binary64
:herbie-target
(if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) -3.5813117084150564e+153) (- (+ z a) b) (if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) 1.2285964308315609e+82) (/ 1.0 (/ (+ (+ x t) y) (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)))) (- (+ z a) b)))
(/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))