| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 6464 |
\[\sqrt{0.125}
\]
(FPCore (v) :precision binary64 (* (* (/ (sqrt 2.0) 4.0) (sqrt (- 1.0 (* 3.0 (* v v))))) (- 1.0 (* v v))))
(FPCore (v) :precision binary64 (sqrt (+ 0.125 (* (* v v) -0.625))))
double code(double v) {
return ((sqrt(2.0) / 4.0) * sqrt((1.0 - (3.0 * (v * v))))) * (1.0 - (v * v));
}
double code(double v) {
return sqrt((0.125 + ((v * v) * -0.625)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = ((sqrt(2.0d0) / 4.0d0) * sqrt((1.0d0 - (3.0d0 * (v * v))))) * (1.0d0 - (v * v))
end function
real(8) function code(v)
real(8), intent (in) :: v
code = sqrt((0.125d0 + ((v * v) * (-0.625d0))))
end function
public static double code(double v) {
return ((Math.sqrt(2.0) / 4.0) * Math.sqrt((1.0 - (3.0 * (v * v))))) * (1.0 - (v * v));
}
public static double code(double v) {
return Math.sqrt((0.125 + ((v * v) * -0.625)));
}
def code(v): return ((math.sqrt(2.0) / 4.0) * math.sqrt((1.0 - (3.0 * (v * v))))) * (1.0 - (v * v))
def code(v): return math.sqrt((0.125 + ((v * v) * -0.625)))
function code(v) return Float64(Float64(Float64(sqrt(2.0) / 4.0) * sqrt(Float64(1.0 - Float64(3.0 * Float64(v * v))))) * Float64(1.0 - Float64(v * v))) end
function code(v) return sqrt(Float64(0.125 + Float64(Float64(v * v) * -0.625))) end
function tmp = code(v) tmp = ((sqrt(2.0) / 4.0) * sqrt((1.0 - (3.0 * (v * v))))) * (1.0 - (v * v)); end
function tmp = code(v) tmp = sqrt((0.125 + ((v * v) * -0.625))); end
code[v_] := N[(N[(N[(N[Sqrt[2.0], $MachinePrecision] / 4.0), $MachinePrecision] * N[Sqrt[N[(1.0 - N[(3.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[v_] := N[Sqrt[N[(0.125 + N[(N[(v * v), $MachinePrecision] * -0.625), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right)
\sqrt{0.125 + \left(v \cdot v\right) \cdot -0.625}
Results
Initial program 100.0%
Simplified100.0%
[Start]100.0 | \[ \left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right)
\] |
|---|---|
associate-*l* [=>]100.0 | \[ \color{blue}{\frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - 3 \cdot \left(v \cdot v\right)} \cdot \left(1 - v \cdot v\right)\right)}
\] |
associate-*r* [=>]100.0 | \[ \frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \color{blue}{\left(3 \cdot v\right) \cdot v}} \cdot \left(1 - v \cdot v\right)\right)
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ \frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)
\] |
|---|---|
add-sqr-sqrt [=>]98.5 | \[ \color{blue}{\sqrt{\frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)} \cdot \sqrt{\frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)}}
\] |
sqrt-unprod [=>]100.0 | \[ \color{blue}{\sqrt{\left(\frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)\right) \cdot \left(\frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)\right)}}
\] |
*-commutative [=>]100.0 | \[ \sqrt{\color{blue}{\left(\left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right) \cdot \frac{\sqrt{2}}{4}\right)} \cdot \left(\frac{\sqrt{2}}{4} \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)\right)}
\] |
*-commutative [=>]100.0 | \[ \sqrt{\left(\left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right) \cdot \frac{\sqrt{2}}{4}\right) \cdot \color{blue}{\left(\left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right) \cdot \frac{\sqrt{2}}{4}\right)}}
\] |
swap-sqr [=>]100.0 | \[ \sqrt{\color{blue}{\left(\left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right) \cdot \left(\sqrt{1 - \left(3 \cdot v\right) \cdot v} \cdot \left(1 - v \cdot v\right)\right)\right) \cdot \left(\frac{\sqrt{2}}{4} \cdot \frac{\sqrt{2}}{4}\right)}}
\] |
Taylor expanded in v around 0 99.5%
Simplified99.5%
[Start]99.5 | \[ \sqrt{\left(1 + -5 \cdot {v}^{2}\right) \cdot 0.125}
\] |
|---|---|
unpow2 [=>]99.5 | \[ \sqrt{\left(1 + -5 \cdot \color{blue}{\left(v \cdot v\right)}\right) \cdot 0.125}
\] |
Applied egg-rr98.0%
[Start]99.5 | \[ \sqrt{\left(1 + -5 \cdot \left(v \cdot v\right)\right) \cdot 0.125}
\] |
|---|---|
expm1-log1p-u [=>]99.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\left(1 + -5 \cdot \left(v \cdot v\right)\right) \cdot 0.125}\right)\right)}
\] |
expm1-udef [=>]98.0 | \[ \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\left(1 + -5 \cdot \left(v \cdot v\right)\right) \cdot 0.125}\right)} - 1}
\] |
+-commutative [=>]98.0 | \[ e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-5 \cdot \left(v \cdot v\right) + 1\right)} \cdot 0.125}\right)} - 1
\] |
fma-def [=>]98.0 | \[ e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\mathsf{fma}\left(-5, v \cdot v, 1\right)} \cdot 0.125}\right)} - 1
\] |
Simplified99.5%
[Start]98.0 | \[ e^{\mathsf{log1p}\left(\sqrt{\mathsf{fma}\left(-5, v \cdot v, 1\right) \cdot 0.125}\right)} - 1
\] |
|---|---|
expm1-def [=>]99.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\mathsf{fma}\left(-5, v \cdot v, 1\right) \cdot 0.125}\right)\right)}
\] |
expm1-log1p [=>]99.5 | \[ \color{blue}{\sqrt{\mathsf{fma}\left(-5, v \cdot v, 1\right) \cdot 0.125}}
\] |
unpow2 [<=]99.5 | \[ \sqrt{\mathsf{fma}\left(-5, \color{blue}{{v}^{2}}, 1\right) \cdot 0.125}
\] |
fma-udef [=>]99.5 | \[ \sqrt{\color{blue}{\left(-5 \cdot {v}^{2} + 1\right)} \cdot 0.125}
\] |
unpow2 [=>]99.5 | \[ \sqrt{\left(-5 \cdot \color{blue}{\left(v \cdot v\right)} + 1\right) \cdot 0.125}
\] |
distribute-lft1-in [<=]99.5 | \[ \sqrt{\color{blue}{\left(-5 \cdot \left(v \cdot v\right)\right) \cdot 0.125 + 0.125}}
\] |
+-commutative [=>]99.5 | \[ \sqrt{\color{blue}{0.125 + \left(-5 \cdot \left(v \cdot v\right)\right) \cdot 0.125}}
\] |
*-commutative [=>]99.5 | \[ \sqrt{0.125 + \color{blue}{\left(\left(v \cdot v\right) \cdot -5\right)} \cdot 0.125}
\] |
unpow2 [<=]99.5 | \[ \sqrt{0.125 + \left(\color{blue}{{v}^{2}} \cdot -5\right) \cdot 0.125}
\] |
associate-*l* [=>]99.5 | \[ \sqrt{0.125 + \color{blue}{{v}^{2} \cdot \left(-5 \cdot 0.125\right)}}
\] |
unpow2 [=>]99.5 | \[ \sqrt{0.125 + \color{blue}{\left(v \cdot v\right)} \cdot \left(-5 \cdot 0.125\right)}
\] |
metadata-eval [=>]99.5 | \[ \sqrt{0.125 + \left(v \cdot v\right) \cdot \color{blue}{-0.625}}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 6464 |
herbie shell --seed 2023140
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 2"
:precision binary64
(* (* (/ (sqrt 2.0) 4.0) (sqrt (- 1.0 (* 3.0 (* v v))))) (- 1.0 (* v v))))