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

Percentage Accurate: 98.0% → 98.0%
Time: 3.3s
Alternatives: 4
Speedup: 1.5×

Specification

?
\[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
(FPCore (x y z t)
  :precision binary64
  :pre TRUE
  (*
 (/ 1.0 3.0)
 (acos (* (/ (* 3.0 (/ x (* y 27.0))) (* z 2.0)) (sqrt t)))))
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)));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
    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
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)));
}
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)))
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
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
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]
f(x, y, z, t):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf],
	t in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z, t: real): real =
	((1) / (3)) * (acos(((((3) * (x / (y * (27)))) / (z * (2))) * (sqrt(t)))))
END code
\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right)

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.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 98.0% accurate, 1.0× speedup?

\[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
(FPCore (x y z t)
  :precision binary64
  :pre TRUE
  (*
 (/ 1.0 3.0)
 (acos (* (/ (* 3.0 (/ x (* y 27.0))) (* z 2.0)) (sqrt t)))))
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)));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
    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
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)));
}
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)))
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
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
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]
f(x, y, z, t):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf],
	t in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z, t: real): real =
	((1) / (3)) * (acos(((((3) * (x / (y * (27)))) / (z * (2))) * (sqrt(t)))))
END code
\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right)

Alternative 1: 98.0% accurate, 1.4× speedup?

\[0.3333333333333333 \cdot \cos^{-1} \left(\sqrt{t} \cdot \left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right)\right) \]
(FPCore (x y z t)
  :precision binary64
  :pre TRUE
  (*
 0.3333333333333333
 (acos (* (sqrt t) (* 0.05555555555555555 (/ (/ x y) z))))))
double code(double x, double y, double z, double t) {
	return 0.3333333333333333 * acos((sqrt(t) * (0.05555555555555555 * ((x / y) / z))));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = 0.3333333333333333d0 * acos((sqrt(t) * (0.05555555555555555d0 * ((x / y) / z))))
end function
public static double code(double x, double y, double z, double t) {
	return 0.3333333333333333 * Math.acos((Math.sqrt(t) * (0.05555555555555555 * ((x / y) / z))));
}
def code(x, y, z, t):
	return 0.3333333333333333 * math.acos((math.sqrt(t) * (0.05555555555555555 * ((x / y) / z))))
function code(x, y, z, t)
	return Float64(0.3333333333333333 * acos(Float64(sqrt(t) * Float64(0.05555555555555555 * Float64(Float64(x / y) / z)))))
end
function tmp = code(x, y, z, t)
	tmp = 0.3333333333333333 * acos((sqrt(t) * (0.05555555555555555 * ((x / y) / z))));
end
code[x_, y_, z_, t_] := N[(0.3333333333333333 * N[ArcCos[N[(N[Sqrt[t], $MachinePrecision] * N[(0.05555555555555555 * N[(N[(x / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(x, y, z, t):
	x in [-inf, +inf],
	y in [-inf, +inf],
	z in [-inf, +inf],
	t in [-inf, +inf]
code: THEORY
BEGIN
f(x, y, z, t: real): real =
	(333333333333333314829616256247390992939472198486328125e-54) * (acos(((sqrt(t)) * ((555555555555555524716027093745651654899120330810546875e-55) * ((x / y) / z)))))
END code
0.3333333333333333 \cdot \cos^{-1} \left(\sqrt{t} \cdot \left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right)\right)
Derivation
  1. Initial program 98.0%

    \[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
  2. Step-by-step derivation
    1. Applied rewrites98.0%

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

    Alternative 2: 98.0% accurate, 1.5× speedup?

    \[0.3333333333333333 \cdot \cos^{-1} \left(\left(\frac{x}{z \cdot y} \cdot 0.05555555555555555\right) \cdot \sqrt{t}\right) \]
    (FPCore (x y z t)
      :precision binary64
      :pre TRUE
      (*
     0.3333333333333333
     (acos (* (* (/ x (* z y)) 0.05555555555555555) (sqrt t)))))
    double code(double x, double y, double z, double t) {
    	return 0.3333333333333333 * acos((((x / (z * y)) * 0.05555555555555555) * sqrt(t)));
    }
    
    real(8) function code(x, y, z, t)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        real(8), intent (in) :: t
        code = 0.3333333333333333d0 * acos((((x / (z * y)) * 0.05555555555555555d0) * sqrt(t)))
    end function
    
    public static double code(double x, double y, double z, double t) {
    	return 0.3333333333333333 * Math.acos((((x / (z * y)) * 0.05555555555555555) * Math.sqrt(t)));
    }
    
    def code(x, y, z, t):
    	return 0.3333333333333333 * math.acos((((x / (z * y)) * 0.05555555555555555) * math.sqrt(t)))
    
    function code(x, y, z, t)
    	return Float64(0.3333333333333333 * acos(Float64(Float64(Float64(x / Float64(z * y)) * 0.05555555555555555) * sqrt(t))))
    end
    
    function tmp = code(x, y, z, t)
    	tmp = 0.3333333333333333 * acos((((x / (z * y)) * 0.05555555555555555) * sqrt(t)));
    end
    
    code[x_, y_, z_, t_] := N[(0.3333333333333333 * N[ArcCos[N[(N[(N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision] * 0.05555555555555555), $MachinePrecision] * N[Sqrt[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
    
    f(x, y, z, t):
    	x in [-inf, +inf],
    	y in [-inf, +inf],
    	z in [-inf, +inf],
    	t in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x, y, z, t: real): real =
    	(333333333333333314829616256247390992939472198486328125e-54) * (acos((((x / (z * y)) * (555555555555555524716027093745651654899120330810546875e-55)) * (sqrt(t)))))
    END code
    0.3333333333333333 \cdot \cos^{-1} \left(\left(\frac{x}{z \cdot y} \cdot 0.05555555555555555\right) \cdot \sqrt{t}\right)
    
    Derivation
    1. Initial program 98.0%

      \[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
    2. Step-by-step derivation
      1. Applied rewrites98.0%

        \[\leadsto 0.3333333333333333 \cdot \cos^{-1} \left(\sqrt{t} \cdot \left(0.05555555555555555 \cdot \frac{\frac{x}{y}}{z}\right)\right) \]
      2. Step-by-step derivation
        1. Applied rewrites98.0%

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

        Alternative 3: 96.8% accurate, 1.5× speedup?

        \[0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{x \cdot \sqrt{t}}{y \cdot z}\right) \]
        (FPCore (x y z t)
          :precision binary64
          :pre TRUE
          (*
         0.3333333333333333
         (acos (* 0.05555555555555555 (/ (* x (sqrt t)) (* y z))))))
        double code(double x, double y, double z, double t) {
        	return 0.3333333333333333 * acos((0.05555555555555555 * ((x * sqrt(t)) / (y * z))));
        }
        
        real(8) function code(x, y, z, t)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8), intent (in) :: t
            code = 0.3333333333333333d0 * acos((0.05555555555555555d0 * ((x * sqrt(t)) / (y * z))))
        end function
        
        public static double code(double x, double y, double z, double t) {
        	return 0.3333333333333333 * Math.acos((0.05555555555555555 * ((x * Math.sqrt(t)) / (y * z))));
        }
        
        def code(x, y, z, t):
        	return 0.3333333333333333 * math.acos((0.05555555555555555 * ((x * math.sqrt(t)) / (y * z))))
        
        function code(x, y, z, t)
        	return Float64(0.3333333333333333 * acos(Float64(0.05555555555555555 * Float64(Float64(x * sqrt(t)) / Float64(y * z)))))
        end
        
        function tmp = code(x, y, z, t)
        	tmp = 0.3333333333333333 * acos((0.05555555555555555 * ((x * sqrt(t)) / (y * z))));
        end
        
        code[x_, y_, z_, t_] := N[(0.3333333333333333 * N[ArcCos[N[(0.05555555555555555 * N[(N[(x * N[Sqrt[t], $MachinePrecision]), $MachinePrecision] / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
        
        f(x, y, z, t):
        	x in [-inf, +inf],
        	y in [-inf, +inf],
        	z in [-inf, +inf],
        	t in [-inf, +inf]
        code: THEORY
        BEGIN
        f(x, y, z, t: real): real =
        	(333333333333333314829616256247390992939472198486328125e-54) * (acos(((555555555555555524716027093745651654899120330810546875e-55) * ((x * (sqrt(t))) / (y * z)))))
        END code
        0.3333333333333333 \cdot \cos^{-1} \left(0.05555555555555555 \cdot \frac{x \cdot \sqrt{t}}{y \cdot z}\right)
        
        Derivation
        1. Initial program 98.0%

          \[\frac{1}{3} \cdot \cos^{-1} \left(\frac{3 \cdot \frac{x}{y \cdot 27}}{z \cdot 2} \cdot \sqrt{t}\right) \]
        2. Taylor expanded in x around 0

          \[\leadsto \frac{1}{3} \cdot \cos^{-1} \left(\frac{1}{18} \cdot \frac{x \cdot \sqrt{t}}{y \cdot z}\right) \]
        3. Step-by-step derivation
          1. Applied rewrites96.8%

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

          Reproduce

          ?
          herbie shell --seed 2026092 
          (FPCore (x y z t)
            :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, D"
            :precision binary64
            (* (/ 1.0 3.0) (acos (* (/ (* 3.0 (/ x (* y 27.0))) (* z 2.0)) (sqrt t)))))