
(FPCore (x y z t a b c i) :precision binary64 (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = 2.0d0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i))
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
def code(x, y, z, t, a, b, c, i): return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i))
function code(x, y, z, t, a, b, c, i) return Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(Float64(Float64(a + Float64(b * c)) * c) * i))) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i)); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b c i) :precision binary64 (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = 2.0d0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i))
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
def code(x, y, z, t, a, b, c, i): return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i))
function code(x, y, z, t, a, b, c, i) return Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(Float64(Float64(a + Float64(b * c)) * c) * i))) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i)); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\end{array}
(FPCore (x y z t a b c i) :precision binary64 (* 2.0 (fma (fma b c a) (- (* c i)) (fma z t (* x y)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * fma(fma(b, c, a), -(c * i), fma(z, t, (x * y)));
}
function code(x, y, z, t, a, b, c, i) return Float64(2.0 * fma(fma(b, c, a), Float64(-Float64(c * i)), fma(z, t, Float64(x * y)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(b * c + a), $MachinePrecision] * (-N[(c * i), $MachinePrecision]) + N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), -c \cdot i, \mathsf{fma}\left(z, t, x \cdot y\right)\right)
\end{array}
Initial program 91.6%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6496.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6496.5
Applied rewrites96.5%
Final simplification96.5%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (* i (* c (+ a (* b c))))))
(if (<= t_1 -4e+123)
(* c (* i (* (fma b c a) -2.0)))
(if (<= t_1 4e+55)
(* 2.0 (fma t z (* x y)))
(if (<= t_1 5e+161)
(* 2.0 (fma z t (- (* a (* c i)))))
(* (* c (* i -2.0)) (fma c b a)))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = i * (c * (a + (b * c)));
double tmp;
if (t_1 <= -4e+123) {
tmp = c * (i * (fma(b, c, a) * -2.0));
} else if (t_1 <= 4e+55) {
tmp = 2.0 * fma(t, z, (x * y));
} else if (t_1 <= 5e+161) {
tmp = 2.0 * fma(z, t, -(a * (c * i)));
} else {
tmp = (c * (i * -2.0)) * fma(c, b, a);
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = Float64(i * Float64(c * Float64(a + Float64(b * c)))) tmp = 0.0 if (t_1 <= -4e+123) tmp = Float64(c * Float64(i * Float64(fma(b, c, a) * -2.0))); elseif (t_1 <= 4e+55) tmp = Float64(2.0 * fma(t, z, Float64(x * y))); elseif (t_1 <= 5e+161) tmp = Float64(2.0 * fma(z, t, Float64(-Float64(a * Float64(c * i))))); else tmp = Float64(Float64(c * Float64(i * -2.0)) * fma(c, b, a)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(i * N[(c * N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+123], N[(c * N[(i * N[(N[(b * c + a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+55], N[(2.0 * N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+161], N[(2.0 * N[(z * t + (-N[(a * N[(c * i), $MachinePrecision]), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(i * -2.0), $MachinePrecision]), $MachinePrecision] * N[(c * b + a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := i \cdot \left(c \cdot \left(a + b \cdot c\right)\right)\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+123}:\\
\;\;\;\;c \cdot \left(i \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot -2\right)\right)\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+55}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+161}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(z, t, -a \cdot \left(c \cdot i\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot \left(i \cdot -2\right)\right) \cdot \mathsf{fma}\left(c, b, a\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < -3.99999999999999991e123Initial program 82.6%
Taylor expanded in i around inf
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
associate-*r*N/A
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
distribute-lft-outN/A
associate-*r*N/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6478.1
Applied rewrites78.1%
if -3.99999999999999991e123 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 4.00000000000000004e55Initial program 99.1%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6488.2
Applied rewrites88.2%
if 4.00000000000000004e55 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 4.9999999999999997e161Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
sub-negN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites89.1%
Taylor expanded in a around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6455.3
Applied rewrites55.3%
if 4.9999999999999997e161 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) Initial program 80.5%
Taylor expanded in x around inf
lower-*.f6412.8
Applied rewrites12.8%
Taylor expanded in i around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6484.9
Applied rewrites84.9%
Final simplification83.3%
(FPCore (x y z t a b c i) :precision binary64 (* 2.0 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - ((a + (b * c)) * (c * i)));
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = 2.0d0 * (((x * y) + (z * t)) - ((a + (b * c)) * (c * i)))
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - ((a + (b * c)) * (c * i)));
}
def code(x, y, z, t, a, b, c, i): return 2.0 * (((x * y) + (z * t)) - ((a + (b * c)) * (c * i)))
function code(x, y, z, t, a, b, c, i) return Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(Float64(a + Float64(b * c)) * Float64(c * i)))) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = 2.0 * (((x * y) + (z * t)) - ((a + (b * c)) * (c * i))); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision] * N[(c * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)
\end{array}
herbie shell --seed 2024222
(FPCore (x y z t a b c i)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A"
:precision binary64
:alt
(! :herbie-platform default (* 2 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i)))))
(* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))