
(FPCore (v) :precision binary64 (/ 4.0 (* (* (* 3.0 PI) (- 1.0 (* v v))) (sqrt (- 2.0 (* 6.0 (* v v)))))))
double code(double v) {
return 4.0 / (((3.0 * ((double) M_PI)) * (1.0 - (v * v))) * sqrt((2.0 - (6.0 * (v * v)))));
}
public static double code(double v) {
return 4.0 / (((3.0 * Math.PI) * (1.0 - (v * v))) * Math.sqrt((2.0 - (6.0 * (v * v)))));
}
def code(v): return 4.0 / (((3.0 * math.pi) * (1.0 - (v * v))) * math.sqrt((2.0 - (6.0 * (v * v)))))
function code(v) return Float64(4.0 / Float64(Float64(Float64(3.0 * pi) * Float64(1.0 - Float64(v * v))) * sqrt(Float64(2.0 - Float64(6.0 * Float64(v * v)))))) end
function tmp = code(v) tmp = 4.0 / (((3.0 * pi) * (1.0 - (v * v))) * sqrt((2.0 - (6.0 * (v * v))))); end
code[v_] := N[(4.0 / N[(N[(N[(3.0 * Pi), $MachinePrecision] * N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(2.0 - N[(6.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{\left(\left(3 \cdot \pi\right) \cdot \left(1 - v \cdot v\right)\right) \cdot \sqrt{2 - 6 \cdot \left(v \cdot v\right)}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v) :precision binary64 (/ 4.0 (* (* (* 3.0 PI) (- 1.0 (* v v))) (sqrt (- 2.0 (* 6.0 (* v v)))))))
double code(double v) {
return 4.0 / (((3.0 * ((double) M_PI)) * (1.0 - (v * v))) * sqrt((2.0 - (6.0 * (v * v)))));
}
public static double code(double v) {
return 4.0 / (((3.0 * Math.PI) * (1.0 - (v * v))) * Math.sqrt((2.0 - (6.0 * (v * v)))));
}
def code(v): return 4.0 / (((3.0 * math.pi) * (1.0 - (v * v))) * math.sqrt((2.0 - (6.0 * (v * v)))))
function code(v) return Float64(4.0 / Float64(Float64(Float64(3.0 * pi) * Float64(1.0 - Float64(v * v))) * sqrt(Float64(2.0 - Float64(6.0 * Float64(v * v)))))) end
function tmp = code(v) tmp = 4.0 / (((3.0 * pi) * (1.0 - (v * v))) * sqrt((2.0 - (6.0 * (v * v))))); end
code[v_] := N[(4.0 / N[(N[(N[(3.0 * Pi), $MachinePrecision] * N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(2.0 - N[(6.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{\left(\left(3 \cdot \pi\right) \cdot \left(1 - v \cdot v\right)\right) \cdot \sqrt{2 - 6 \cdot \left(v \cdot v\right)}}
\end{array}
(FPCore (v) :precision binary64 (/ (/ (/ -1.3333333333333333 (fma v v -1.0)) PI) (sqrt (fma v (* v -6.0) 2.0))))
double code(double v) {
return ((-1.3333333333333333 / fma(v, v, -1.0)) / ((double) M_PI)) / sqrt(fma(v, (v * -6.0), 2.0));
}
function code(v) return Float64(Float64(Float64(-1.3333333333333333 / fma(v, v, -1.0)) / pi) / sqrt(fma(v, Float64(v * -6.0), 2.0))) end
code[v_] := N[(N[(N[(-1.3333333333333333 / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision] / N[Sqrt[N[(v * N[(v * -6.0), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{-1.3333333333333333}{\mathsf{fma}\left(v, v, -1\right)}}{\pi}}{\sqrt{\mathsf{fma}\left(v, v \cdot -6, 2\right)}}
\end{array}
Initial program 98.4%
associate-/r*100.0%
associate-*l*100.0%
associate-/r*100.0%
associate-/l/100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
associate-/r*100.0%
metadata-eval100.0%
metadata-eval100.0%
fma-neg100.0%
metadata-eval100.0%
sub-neg100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (v) :precision binary64 (/ 1.3333333333333333 (* (- 1.0 (* v v)) (* PI (sqrt (fma v (* v -6.0) 2.0))))))
double code(double v) {
return 1.3333333333333333 / ((1.0 - (v * v)) * (((double) M_PI) * sqrt(fma(v, (v * -6.0), 2.0))));
}
function code(v) return Float64(1.3333333333333333 / Float64(Float64(1.0 - Float64(v * v)) * Float64(pi * sqrt(fma(v, Float64(v * -6.0), 2.0))))) end
code[v_] := N[(1.3333333333333333 / N[(N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision] * N[(Pi * N[Sqrt[N[(v * N[(v * -6.0), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1.3333333333333333}{\left(1 - v \cdot v\right) \cdot \left(\pi \cdot \sqrt{\mathsf{fma}\left(v, v \cdot -6, 2\right)}\right)}
\end{array}
Initial program 98.4%
expm1-log1p-u98.4%
expm1-udef98.4%
Applied egg-rr98.4%
expm1-def98.4%
expm1-log1p98.4%
associate-/r*100.0%
associate-/r*100.0%
associate-/r*100.0%
metadata-eval100.0%
associate-/r*100.0%
associate-/r*100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (v) :precision binary64 (/ (/ 1.3333333333333333 (* PI (- 1.0 (* v v)))) (sqrt (+ 2.0 (* -6.0 (* v v))))))
double code(double v) {
return (1.3333333333333333 / (((double) M_PI) * (1.0 - (v * v)))) / sqrt((2.0 + (-6.0 * (v * v))));
}
public static double code(double v) {
return (1.3333333333333333 / (Math.PI * (1.0 - (v * v)))) / Math.sqrt((2.0 + (-6.0 * (v * v))));
}
def code(v): return (1.3333333333333333 / (math.pi * (1.0 - (v * v)))) / math.sqrt((2.0 + (-6.0 * (v * v))))
function code(v) return Float64(Float64(1.3333333333333333 / Float64(pi * Float64(1.0 - Float64(v * v)))) / sqrt(Float64(2.0 + Float64(-6.0 * Float64(v * v))))) end
function tmp = code(v) tmp = (1.3333333333333333 / (pi * (1.0 - (v * v)))) / sqrt((2.0 + (-6.0 * (v * v)))); end
code[v_] := N[(N[(1.3333333333333333 / N[(Pi * N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(2.0 + N[(-6.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1.3333333333333333}{\pi \cdot \left(1 - v \cdot v\right)}}{\sqrt{2 + -6 \cdot \left(v \cdot v\right)}}
\end{array}
Initial program 98.4%
associate-/r*100.0%
associate-*l*100.0%
associate-/r*100.0%
metadata-eval100.0%
sub-neg100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (v) :precision binary64 (/ (/ 1.0 (/ PI 1.3333333333333333)) (sqrt (+ 2.0 (* -6.0 (* v v))))))
double code(double v) {
return (1.0 / (((double) M_PI) / 1.3333333333333333)) / sqrt((2.0 + (-6.0 * (v * v))));
}
public static double code(double v) {
return (1.0 / (Math.PI / 1.3333333333333333)) / Math.sqrt((2.0 + (-6.0 * (v * v))));
}
def code(v): return (1.0 / (math.pi / 1.3333333333333333)) / math.sqrt((2.0 + (-6.0 * (v * v))))
function code(v) return Float64(Float64(1.0 / Float64(pi / 1.3333333333333333)) / sqrt(Float64(2.0 + Float64(-6.0 * Float64(v * v))))) end
function tmp = code(v) tmp = (1.0 / (pi / 1.3333333333333333)) / sqrt((2.0 + (-6.0 * (v * v)))); end
code[v_] := N[(N[(1.0 / N[(Pi / 1.3333333333333333), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(2.0 + N[(-6.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\frac{\pi}{1.3333333333333333}}}{\sqrt{2 + -6 \cdot \left(v \cdot v\right)}}
\end{array}
Initial program 98.4%
associate-/r*100.0%
associate-*l*100.0%
associate-/r*100.0%
metadata-eval100.0%
sub-neg100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in v around 0 99.2%
clear-num99.2%
inv-pow99.2%
Applied egg-rr99.2%
unpow-199.2%
Simplified99.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (/ (/ 1.3333333333333333 PI) (sqrt (+ 2.0 (* -6.0 (* v v))))))
double code(double v) {
return (1.3333333333333333 / ((double) M_PI)) / sqrt((2.0 + (-6.0 * (v * v))));
}
public static double code(double v) {
return (1.3333333333333333 / Math.PI) / Math.sqrt((2.0 + (-6.0 * (v * v))));
}
def code(v): return (1.3333333333333333 / math.pi) / math.sqrt((2.0 + (-6.0 * (v * v))))
function code(v) return Float64(Float64(1.3333333333333333 / pi) / sqrt(Float64(2.0 + Float64(-6.0 * Float64(v * v))))) end
function tmp = code(v) tmp = (1.3333333333333333 / pi) / sqrt((2.0 + (-6.0 * (v * v)))); end
code[v_] := N[(N[(1.3333333333333333 / Pi), $MachinePrecision] / N[Sqrt[N[(2.0 + N[(-6.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1.3333333333333333}{\pi}}{\sqrt{2 + -6 \cdot \left(v \cdot v\right)}}
\end{array}
Initial program 98.4%
associate-/r*100.0%
associate-*l*100.0%
associate-/r*100.0%
metadata-eval100.0%
sub-neg100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in v around 0 99.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (/ 1.3333333333333333 (* PI (sqrt 2.0))))
double code(double v) {
return 1.3333333333333333 / (((double) M_PI) * sqrt(2.0));
}
public static double code(double v) {
return 1.3333333333333333 / (Math.PI * Math.sqrt(2.0));
}
def code(v): return 1.3333333333333333 / (math.pi * math.sqrt(2.0))
function code(v) return Float64(1.3333333333333333 / Float64(pi * sqrt(2.0))) end
function tmp = code(v) tmp = 1.3333333333333333 / (pi * sqrt(2.0)); end
code[v_] := N[(1.3333333333333333 / N[(Pi * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1.3333333333333333}{\pi \cdot \sqrt{2}}
\end{array}
Initial program 98.4%
expm1-log1p-u98.4%
expm1-udef98.4%
Applied egg-rr98.4%
expm1-def98.4%
expm1-log1p98.4%
associate-/r*100.0%
associate-/r*100.0%
associate-/r*100.0%
metadata-eval100.0%
associate-/r*100.0%
associate-/r*100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in v around 0 99.1%
Final simplification99.1%
herbie shell --seed 2023257
(FPCore (v)
:name "Falkner and Boettcher, Equation (22+)"
:precision binary64
(/ 4.0 (* (* (* 3.0 PI) (- 1.0 (* v v))) (sqrt (- 2.0 (* 6.0 (* v v)))))))