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

?

Percentage Accurate: 90.4% → 96.8%
Time: 19.2s
Precision: binary64
Cost: 2372

?

\[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\\ t_2 := z \cdot t + x \cdot y\\ \mathbf{if}\;t_2 - i \cdot \left(c \cdot t_1\right) \leq \infty:\\ \;\;\;\;2 \cdot \left(t_2 - 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))) (t_2 (+ (* z t) (* x y))))
   (if (<= (- t_2 (* i (* c t_1))) INFINITY)
     (* 2.0 (- t_2 (* 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 t_2 = (z * t) + (x * y);
	double tmp;
	if ((t_2 - (i * (c * t_1))) <= ((double) INFINITY)) {
		tmp = 2.0 * (t_2 - (t_1 * (c * i)));
	} else {
		tmp = 2.0 * (c * (t_1 * -i));
	}
	return tmp;
}
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));
}
public static 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 t_2 = (z * t) + (x * y);
	double tmp;
	if ((t_2 - (i * (c * t_1))) <= Double.POSITIVE_INFINITY) {
		tmp = 2.0 * (t_2 - (t_1 * (c * i)));
	} else {
		tmp = 2.0 * (c * (t_1 * -i));
	}
	return tmp;
}
def code(x, y, z, t, a, b, c, i):
	return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i))
def code(x, y, z, t, a, b, c, i):
	t_1 = a + (b * c)
	t_2 = (z * t) + (x * y)
	tmp = 0
	if (t_2 - (i * (c * t_1))) <= math.inf:
		tmp = 2.0 * (t_2 - (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))
	t_2 = Float64(Float64(z * t) + Float64(x * y))
	tmp = 0.0
	if (Float64(t_2 - Float64(i * Float64(c * t_1))) <= Inf)
		tmp = Float64(2.0 * Float64(t_2 - Float64(t_1 * Float64(c * i))));
	else
		tmp = Float64(2.0 * Float64(c * Float64(t_1 * Float64(-i))));
	end
	return tmp
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
function tmp_2 = code(x, y, z, t, a, b, c, i)
	t_1 = a + (b * c);
	t_2 = (z * t) + (x * y);
	tmp = 0.0;
	if ((t_2 - (i * (c * t_1))) <= Inf)
		tmp = 2.0 * (t_2 - (t_1 * (c * i)));
	else
		tmp = 2.0 * (c * (t_1 * -i));
	end
	tmp_2 = 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]}, Block[{t$95$2 = N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$2 - N[(i * N[(c * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(2.0 * N[(t$95$2 - 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\\
t_2 := z \cdot t + x \cdot y\\
\mathbf{if}\;t_2 - i \cdot \left(c \cdot t_1\right) \leq \infty:\\
\;\;\;\;2 \cdot \left(t_2 - 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 vs ?

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 19 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original90.4%
Target94.7%
Herbie96.8%
\[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 96.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. Simplified98.4%

      \[\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]96.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) \]

      associate-*l* [=>]98.4%

      \[ 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 [=>]98.4%

      \[ 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) \]
    3. Applied egg-rr98.4%

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

      [Start]98.4%

      \[ 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) \]

      fma-def [<=]98.4%

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

      +-commutative [=>]98.4%

      \[ 2 \cdot \left(\color{blue}{\left(z \cdot t + x \cdot y\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 44.3%

      \[\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.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(z \cdot t + x \cdot y\right) - i \cdot \left(c \cdot \left(a + b \cdot c\right)\right) \leq \infty:\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\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
Accuracy96.8%
Cost2372
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := z \cdot t + x \cdot y\\ \mathbf{if}\;t_2 - i \cdot \left(c \cdot t_1\right) \leq \infty:\\ \;\;\;\;2 \cdot \left(t_2 - 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} \]
Alternative 2
Accuracy95.1%
Cost7488
\[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) \]
Alternative 3
Accuracy93.0%
Cost2372
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := \left(z \cdot t + x \cdot y\right) - i \cdot \left(c \cdot t_1\right)\\ \mathbf{if}\;t_2 \leq \infty:\\ \;\;\;\;2 \cdot t_2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(c \cdot \left(t_1 \cdot \left(-i\right)\right)\right)\\ \end{array} \]
Alternative 4
Accuracy83.7%
Cost1616
\[\begin{array}{l} t_1 := z \cdot t + x \cdot y\\ \mathbf{if}\;c \leq -1.4 \cdot 10^{+148}:\\ \;\;\;\;2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{-69}:\\ \;\;\;\;2 \cdot \left(t_1 - i \cdot \left(a \cdot c\right)\right)\\ \mathbf{elif}\;c \leq 35000000000000:\\ \;\;\;\;2 \cdot \left(t_1 - i \cdot \left(b \cdot \left(c \cdot c\right)\right)\right)\\ \mathbf{elif}\;c \leq 3 \cdot 10^{+39}:\\ \;\;\;\;2 \cdot \left(z \cdot t - a \cdot \left(c \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\ \end{array} \]
Alternative 5
Accuracy84.6%
Cost1352
\[\begin{array}{l} t_1 := z \cdot t + x \cdot y\\ \mathbf{if}\;c \leq -9.5 \cdot 10^{+147}:\\ \;\;\;\;2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \mathbf{elif}\;c \leq 2.5 \cdot 10^{-16}:\\ \;\;\;\;2 \cdot \left(t_1 - i \cdot \left(a \cdot c\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\ \end{array} \]
Alternative 6
Accuracy64.6%
Cost1232
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - a \cdot \left(c \cdot i\right)\right)\\ \mathbf{if}\;c \leq -1.95 \cdot 10^{+149}:\\ \;\;\;\;\left(i \cdot \left(c \cdot c\right)\right) \cdot \left(b \cdot -2\right)\\ \mathbf{elif}\;c \leq -13.8:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-247}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(i \cdot \left(c \cdot \left(b \cdot \left(-c\right)\right)\right)\right)\\ \end{array} \]
Alternative 7
Accuracy63.4%
Cost1232
\[\begin{array}{l} t_1 := a \cdot \left(c \cdot i\right)\\ \mathbf{if}\;c \leq -6.5 \cdot 10^{+147}:\\ \;\;\;\;\left(i \cdot \left(c \cdot c\right)\right) \cdot \left(b \cdot -2\right)\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-140}:\\ \;\;\;\;2 \cdot \left(x \cdot y - t_1\right)\\ \mathbf{elif}\;c \leq 1.04 \cdot 10^{-247}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{elif}\;c \leq 9 \cdot 10^{+51}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_1\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(i \cdot \left(c \cdot \left(b \cdot \left(-c\right)\right)\right)\right)\\ \end{array} \]
Alternative 8
Accuracy84.3%
Cost1225
\[\begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+148} \lor \neg \left(c \leq 3 \cdot 10^{+99}\right):\\ \;\;\;\;2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - i \cdot \left(a \cdot c\right)\right)\\ \end{array} \]
Alternative 9
Accuracy72.7%
Cost1033
\[\begin{array}{l} \mathbf{if}\;c \leq -19 \lor \neg \left(c \leq 3 \cdot 10^{-105}\right):\\ \;\;\;\;2 \cdot \left(c \cdot \left(\left(a + b \cdot c\right) \cdot \left(-i\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 10
Accuracy35.7%
Cost976
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y\right)\\ t_2 := \left(a \cdot c\right) \cdot \left(i \cdot -2\right)\\ \mathbf{if}\;i \leq -1.22 \cdot 10^{-12}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq -4.3 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 2.2 \cdot 10^{-121}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;i \leq 5.5 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Accuracy36.8%
Cost908
\[\begin{array}{l} t_1 := 2 \cdot \left(a \cdot \left(c \cdot \left(-i\right)\right)\right)\\ \mathbf{if}\;a \leq -3.3 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2 \cdot 10^{-32}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;a \leq 10^{+100}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Accuracy68.3%
Cost904
\[\begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{+104}:\\ \;\;\;\;\left(i \cdot \left(c \cdot c\right)\right) \cdot \left(b \cdot -2\right)\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{+151}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(i \cdot \left(c \cdot \left(b \cdot \left(-c\right)\right)\right)\right)\\ \end{array} \]
Alternative 13
Accuracy68.6%
Cost904
\[\begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{+104}:\\ \;\;\;\;\left(i \cdot \left(c \cdot c\right)\right) \cdot \left(b \cdot -2\right)\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{+151}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\left(i \cdot \left(b \cdot c\right)\right) \cdot \left(-c\right)\right)\\ \end{array} \]
Alternative 14
Accuracy35.5%
Cost844
\[\begin{array}{l} t_1 := \left(c \cdot -2\right) \cdot \left(a \cdot i\right)\\ \mathbf{if}\;a \leq -1.1 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -6.6 \cdot 10^{-31}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;a \leq 1.7 \cdot 10^{+100}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Accuracy56.6%
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -6 \cdot 10^{+103} \lor \neg \left(a \leq 1.35 \cdot 10^{+184}\right):\\ \;\;\;\;2 \cdot \left(a \cdot \left(c \cdot \left(-i\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 16
Accuracy68.3%
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+147} \lor \neg \left(c \leq 1.7 \cdot 10^{+151}\right):\\ \;\;\;\;\left(c \cdot \left(b \cdot i\right)\right) \cdot \left(c \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 17
Accuracy68.5%
Cost840
\[\begin{array}{l} \mathbf{if}\;c \leq -3.5 \cdot 10^{+104}:\\ \;\;\;\;\left(i \cdot \left(c \cdot c\right)\right) \cdot \left(b \cdot -2\right)\\ \mathbf{elif}\;c \leq 9 \cdot 10^{+150}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(c \cdot \left(b \cdot i\right)\right) \cdot \left(c \cdot -2\right)\\ \end{array} \]
Alternative 18
Accuracy39.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;t \leq -1.7 \cdot 10^{-61} \lor \neg \left(t \leq 1.6 \cdot 10^{+58}\right):\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 19
Accuracy29.1%
Cost320
\[2 \cdot \left(z \cdot t\right) \]

Reproduce?

herbie shell --seed 2023272 
(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))))