Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A

?

Percentage Accurate: 90.2% → 96.4%
Time: 21.7s
Precision: binary64
Cost: 8644

?

\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
\[\begin{array}{l} t_1 := a + b \cdot c\\ \mathbf{if}\;\left(z \cdot t + x \cdot y\right) - \left(c \cdot t_1\right) \cdot i \leq \infty:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - t_1 \cdot \left(c \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(c \cdot \left(t_1 \cdot \left(-i\right)\right)\right)\\ \end{array} \]
(FPCore (x y z t a b c i)
 :precision binary64
 (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
(FPCore (x y z t a b c i)
 :precision binary64
 (let* ((t_1 (+ a (* b c))))
   (if (<= (- (+ (* z t) (* x y)) (* (* c t_1) i)) INFINITY)
     (* 2.0 (- (fma x y (* z t)) (* t_1 (* c i))))
     (* 2.0 (* c (* t_1 (- 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));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	double t_1 = a + (b * c);
	double tmp;
	if ((((z * t) + (x * y)) - ((c * t_1) * i)) <= ((double) INFINITY)) {
		tmp = 2.0 * (fma(x, y, (z * t)) - (t_1 * (c * i)));
	} else {
		tmp = 2.0 * (c * (t_1 * -i));
	}
	return tmp;
}
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 code(x, y, z, t, a, b, c, i)
	t_1 = Float64(a + Float64(b * c))
	tmp = 0.0
	if (Float64(Float64(Float64(z * t) + Float64(x * y)) - Float64(Float64(c * t_1) * i)) <= Inf)
		tmp = Float64(2.0 * Float64(fma(x, y, Float64(z * t)) - Float64(t_1 * Float64(c * i))));
	else
		tmp = Float64(2.0 * Float64(c * Float64(t_1 * Float64(-i))));
	end
	return tmp
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]
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] - N[(N[(c * t$95$1), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision], Infinity], N[(2.0 * N[(N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * N[(c * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(c * N[(t$95$1 * (-i)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\begin{array}{l}
t_1 := a + b \cdot c\\
\mathbf{if}\;\left(z \cdot t + x \cdot y\right) - \left(c \cdot t_1\right) \cdot i \leq \infty:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - t_1 \cdot \left(c \cdot i\right)\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(c \cdot \left(t_1 \cdot \left(-i\right)\right)\right)\\


\end{array}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 13 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Target

Original90.2%
Target94.2%
Herbie96.4%
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right) \]

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)) < +inf.0

    1. Initial program 91.6%

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
    2. Simplified97.9%

      \[\leadsto \color{blue}{2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)} \]
      Step-by-step derivation

      [Start]91.6

      \[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]

      associate-*l* [=>]97.9

      \[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{\left(a + b \cdot c\right) \cdot \left(c \cdot i\right)}\right) \]

      fma-def [=>]97.9

      \[ 2 \cdot \left(\color{blue}{\mathsf{fma}\left(x, y, z \cdot t\right)} - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right) \]

    if +inf.0 < (-.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i))

    1. Initial program 0.0%

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
    2. Taylor expanded in i around inf 61.5%

      \[\leadsto 2 \cdot \color{blue}{\left(-1 \cdot \left(c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(z \cdot t + x \cdot y\right) - \left(c \cdot \left(a + b \cdot c\right)\right) \cdot i \leq \infty:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy94.9%
Cost2504
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := \left(c \cdot t_1\right) \cdot i\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+304}:\\ \;\;\;\;2 \cdot \left(c \cdot \left(t_1 \cdot \left(-i\right)\right)\right)\\ \mathbf{elif}\;t_2 \leq 10^{+307}:\\ \;\;\;\;\left(\left(z \cdot t + x \cdot y\right) - t_2\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(t_1 \cdot i\right)\right)\\ \end{array} \]
Alternative 2
Accuracy67.4%
Cost1364
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - c \cdot \left(a \cdot i\right)\right)\\ t_2 := -2 \cdot \left(b \cdot \left(c \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{if}\;c \leq -2.4 \cdot 10^{+66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -2 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -3.7 \cdot 10^{-21}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 1.95 \cdot 10^{-75}:\\ \;\;\;\;\left(z \cdot t + x \cdot y\right) \cdot 2\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{+116}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy73.0%
Cost1361
\[\begin{array}{l} t_1 := 2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \mathbf{if}\;c \leq -7.3 \cdot 10^{-22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-65}:\\ \;\;\;\;\left(z \cdot t + x \cdot y\right) \cdot 2\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{+65} \lor \neg \left(c \leq 3.65 \cdot 10^{+137}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ \end{array} \]
Alternative 4
Accuracy78.9%
Cost1356
\[\begin{array}{l} t_1 := c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\\ t_2 := 2 \cdot \left(x \cdot y - t_1\right)\\ \mathbf{if}\;c \leq -1.1 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{-138}:\\ \;\;\;\;\left(z \cdot t + x \cdot y\right) \cdot 2\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{+64}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_1\right)\\ \end{array} \]
Alternative 5
Accuracy73.2%
Cost1298
\[\begin{array}{l} \mathbf{if}\;c \leq -4.8 \cdot 10^{-21} \lor \neg \left(c \leq 2.5 \cdot 10^{-64}\right) \land \left(c \leq 2.05 \cdot 10^{+67} \lor \neg \left(c \leq 2.4 \cdot 10^{+80}\right)\right):\\ \;\;\;\;2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot t + x \cdot y\right) \cdot 2\\ \end{array} \]
Alternative 6
Accuracy79.9%
Cost1225
\[\begin{array}{l} \mathbf{if}\;c \leq -5.2 \cdot 10^{-65} \lor \neg \left(c \leq 6.2 \cdot 10^{-76}\right):\\ \;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot t + x \cdot y\right) \cdot 2\\ \end{array} \]
Alternative 7
Accuracy85.8%
Cost1224
\[\begin{array}{l} t_1 := c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\\ \mathbf{if}\;c \leq -2.15 \cdot 10^{-48}:\\ \;\;\;\;2 \cdot \left(x \cdot y - t_1\right)\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-64}:\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - a \cdot \left(c \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_1\right)\\ \end{array} \]
Alternative 8
Accuracy49.0%
Cost1104
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y\right)\\ t_2 := -2 \cdot \left(b \cdot \left(c \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{if}\;c \leq -2.9 \cdot 10^{-22}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 5.4 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{-171}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;c \leq 2.65 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Accuracy65.9%
Cost1104
\[\begin{array}{l} t_1 := \left(z \cdot t + x \cdot y\right) \cdot 2\\ t_2 := -2 \cdot \left(b \cdot \left(c \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{if}\;c \leq -5.5 \cdot 10^{+37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{+50}:\\ \;\;\;\;2 \cdot \left(i \cdot \left(c \cdot \left(-a\right)\right)\right)\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{+116}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Accuracy38.2%
Cost844
\[\begin{array}{l} t_1 := a \cdot \left(\left(c \cdot i\right) \cdot -2\right)\\ \mathbf{if}\;a \leq -1.4 \cdot 10^{+74}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 9.5 \cdot 10^{-81}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;a \leq 1.75 \cdot 10^{+72}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Accuracy39.6%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-22} \lor \neg \left(x \leq 3.9 \cdot 10^{-75}\right):\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \end{array} \]
Alternative 12
Accuracy28.7%
Cost320
\[2 \cdot \left(z \cdot t\right) \]

Reproduce?

herbie shell --seed 2023161 
(FPCore (x y z t a b c i)
  :name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A"
  :precision binary64

  :herbie-target
  (* 2.0 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i))))

  (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))