Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, D

?

Percentage Accurate: 97.9% → 99.5%
Time: 10.0s
Precision: binary64
Cost: 26560

?

\[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
\[\begin{array}{l} [y, z] = \mathsf{sort}([y, z])\\ \\ e^{0.3333333333333333 \cdot \left(3 \cdot \log \left(0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\right)\right)\right)} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (* (/ 1.0 3.0) (acos (* (/ (* 3.0 (/ x (* y 27.0))) (* z 2.0)) (sqrt t)))))
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (exp
  (*
   0.3333333333333333
   (*
    3.0
    (log
     (*
      0.3333333333333333
      (acos (* 0.05555555555555555 (/ (sqrt t) (* z (/ y x)))))))))))
double code(double x, double y, double z, double t) {
	return (1.0 / 3.0) * acos((((3.0 * (x / (y * 27.0))) / (z * 2.0)) * sqrt(t)));
}
assert(y < z);
double code(double x, double y, double z, double t) {
	return exp((0.3333333333333333 * (3.0 * log((0.3333333333333333 * acos((0.05555555555555555 * (sqrt(t) / (z * (y / x))))))))));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (1.0d0 / 3.0d0) * acos((((3.0d0 * (x / (y * 27.0d0))) / (z * 2.0d0)) * sqrt(t)))
end function
NOTE: y and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = exp((0.3333333333333333d0 * (3.0d0 * log((0.3333333333333333d0 * acos((0.05555555555555555d0 * (sqrt(t) / (z * (y / x))))))))))
end function
public static double code(double x, double y, double z, double t) {
	return (1.0 / 3.0) * Math.acos((((3.0 * (x / (y * 27.0))) / (z * 2.0)) * Math.sqrt(t)));
}
assert y < z;
public static double code(double x, double y, double z, double t) {
	return Math.exp((0.3333333333333333 * (3.0 * Math.log((0.3333333333333333 * Math.acos((0.05555555555555555 * (Math.sqrt(t) / (z * (y / x))))))))));
}
def code(x, y, z, t):
	return (1.0 / 3.0) * math.acos((((3.0 * (x / (y * 27.0))) / (z * 2.0)) * math.sqrt(t)))
[y, z] = sort([y, z])
def code(x, y, z, t):
	return math.exp((0.3333333333333333 * (3.0 * math.log((0.3333333333333333 * math.acos((0.05555555555555555 * (math.sqrt(t) / (z * (y / x))))))))))
function code(x, y, z, t)
	return Float64(Float64(1.0 / 3.0) * acos(Float64(Float64(Float64(3.0 * Float64(x / Float64(y * 27.0))) / Float64(z * 2.0)) * sqrt(t))))
end
y, z = sort([y, z])
function code(x, y, z, t)
	return exp(Float64(0.3333333333333333 * Float64(3.0 * log(Float64(0.3333333333333333 * acos(Float64(0.05555555555555555 * Float64(sqrt(t) / Float64(z * Float64(y / x))))))))))
end
function tmp = code(x, y, z, t)
	tmp = (1.0 / 3.0) * acos((((3.0 * (x / (y * 27.0))) / (z * 2.0)) * sqrt(t)));
end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z, t)
	tmp = exp((0.3333333333333333 * (3.0 * log((0.3333333333333333 * acos((0.05555555555555555 * (sqrt(t) / (z * (y / x))))))))));
end
code[x_, y_, z_, t_] := N[(N[(1.0 / 3.0), $MachinePrecision] * N[ArcCos[N[(N[(N[(3.0 * N[(x / N[(y * 27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(z * 2.0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := N[Exp[N[(0.3333333333333333 * N[(3.0 * N[Log[N[(0.3333333333333333 * N[ArcCos[N[(0.05555555555555555 * N[(N[Sqrt[t], $MachinePrecision] / N[(z * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right)
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
e^{0.3333333333333333 \cdot \left(3 \cdot \log \left(0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\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 4 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

Original97.9%
Target98.2%
Herbie99.5%
\[\frac{\cos^{-1} \left(\frac{\frac{x}{27}}{y \cdot z} \cdot \frac{\sqrt{t}}{\frac{2}{3}}\right)}{3} \]

Derivation?

  1. Initial program 98.1%

    \[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
  2. Simplified98.1%

    \[\leadsto \color{blue}{0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)} \]
    Step-by-step derivation

    [Start]98.1%

    \[ \frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]

    metadata-eval [=>]98.1%

    \[ \color{blue}{0.3333333333333333} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]

    associate-*r/ [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\frac{\color{blue}{\frac{3 \cdot x}{y \cdot 27}}}{z \cdot 2} \cdot \sqrt{t}\right) \]

    *-commutative [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\frac{\frac{3 \cdot x}{\color{blue}{27 \cdot y}}}{z \cdot 2} \cdot \sqrt{t}\right) \]

    times-frac [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\frac{\color{blue}{\frac{3}{27} \cdot \frac{x}{y}}}{z \cdot 2} \cdot \sqrt{t}\right) \]

    *-commutative [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\frac{\frac{3}{27} \cdot \frac{x}{y}}{\color{blue}{2 \cdot z}} \cdot \sqrt{t}\right) \]

    times-frac [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\color{blue}{\left(\frac{\frac{3}{27}}{2} \cdot \frac{\frac{x}{y}}{z}\right)} \cdot \sqrt{t}\right) \]

    metadata-eval [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\left(\frac{\color{blue}{0.1111111111111111}}{2} \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right) \]

    metadata-eval [=>]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\left(\color{blue}{0.05555555555555555} \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right) \]
  3. Applied egg-rr99.6%

    \[\leadsto \color{blue}{e^{\left(3 \cdot \log \left(0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\right)\right)\right) \cdot 0.3333333333333333}} \]
    Step-by-step derivation

    [Start]98.1%

    \[ 0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right) \]

    add-cbrt-cube [=>]98.1%

    \[ \color{blue}{\sqrt[3]{\left(\left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)}} \]

    pow1/3 [=>]98.1%

    \[ \color{blue}{{\left(\left(\left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right)}^{0.3333333333333333}} \]

    add-exp-log [=>]98.1%

    \[ {\color{blue}{\left(e^{\log \left(\left(\left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right)}\right)}}^{0.3333333333333333} \]

    pow-exp [=>]98.1%

    \[ \color{blue}{e^{\log \left(\left(\left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \cos^{-1} \left(\left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right) \cdot \sqrt{t}\right)\right)\right) \cdot 0.3333333333333333}} \]
  4. Final simplification99.6%

    \[\leadsto e^{0.3333333333333333 \cdot \left(3 \cdot \log \left(0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\right)\right)\right)} \]

Alternatives

Alternative 1
Accuracy99.5%
Cost26560
\[e^{0.3333333333333333 \cdot \left(3 \cdot \log \left(0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\right)\right)\right)} \]
Alternative 2
Accuracy99.4%
Cost26432
\[e^{\mathsf{log1p}\left(0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\right)\right)} + -1 \]
Alternative 3
Accuracy98.0%
Cost26368
\[{\left(\sqrt{0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{\sqrt{t}}{z \cdot \frac{y}{x}}\right)}\right)}^{2} \]
Alternative 4
Accuracy97.9%
Cost13504
\[0.3333333333333333 \cdot \cos^{-1} \left(\sqrt{t} \cdot \left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right)\right) \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (x y z t)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, D"
  :precision binary64

  :herbie-target
  (/ (acos (* (/ (/ x 27.0) (* y z)) (/ (sqrt t) (/ 2.0 3.0)))) 3.0)

  (* (/ 1.0 3.0) (acos (* (/ (* 3.0 (/ x (* y 27.0))) (* z 2.0)) (sqrt t)))))