PI*r^2

Percentage Accurate: 99.7% → 99.7%
Time: 19.1s
Alternatives: 3
Speedup: N/A×

Specification

?
\[0 \leq r \land r \leq 1.79 \cdot 10^{+308}\]
\[\begin{array}{l} \\ \mathsf{PI}\left(\right) \cdot {r}^{2} \end{array} \]
(FPCore (r) :precision binary64 (* (PI) (pow r 2.0)))
\begin{array}{l}

\\
\mathsf{PI}\left(\right) \cdot {r}^{2}
\end{array}

Sampling outcomes in binary64 precision:

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 3 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: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{PI}\left(\right) \cdot {r}^{2} \end{array} \]
(FPCore (r) :precision binary64 (* (PI) (pow r 2.0)))
\begin{array}{l}

\\
\mathsf{PI}\left(\right) \cdot {r}^{2}
\end{array}

Alternative 1: 99.7% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \left(r \cdot r\right) \cdot \mathsf{PI}\left(\right) \end{array} \]
(FPCore (r) :precision binary64 (* (* r r) (PI)))
\begin{array}{l}

\\
\left(r \cdot r\right) \cdot \mathsf{PI}\left(\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[\mathsf{PI}\left(\right) \cdot {r}^{2} \]
  2. Add Preprocessing
  3. Applied rewrites99.8%

    \[\leadsto \color{blue}{\left(r \cdot r\right) \cdot \mathsf{PI}\left(\right)} \]
  4. Add Preprocessing

Alternative 2: 99.7% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \left(\mathsf{PI}\left(\right) \cdot r\right) \cdot r \end{array} \]
(FPCore (r) :precision binary64 (* (* (PI) r) r))
\begin{array}{l}

\\
\left(\mathsf{PI}\left(\right) \cdot r\right) \cdot r
\end{array}
Derivation
  1. Initial program 99.8%

    \[\mathsf{PI}\left(\right) \cdot {r}^{2} \]
  2. Add Preprocessing
  3. Taylor expanded in r around 0

    \[\leadsto \color{blue}{{r}^{2} \cdot \mathsf{PI}\left(\right)} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot {r}^{2}} \]
    2. unpow2N/A

      \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{\left(r \cdot r\right)} \]
    3. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\mathsf{PI}\left(\right) \cdot r\right) \cdot r} \]
    4. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\mathsf{PI}\left(\right) \cdot r\right) \cdot r} \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\mathsf{PI}\left(\right) \cdot r\right)} \cdot r \]
    6. lower-PI.f6499.7

      \[\leadsto \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot r\right) \cdot r \]
  5. Applied rewrites99.7%

    \[\leadsto \color{blue}{\left(\mathsf{PI}\left(\right) \cdot r\right) \cdot r} \]
  6. Add Preprocessing

Alternative 3: 57.6% accurate, 17.8× speedup?

\[\begin{array}{l} \\ r \cdot r \end{array} \]
(FPCore (r) :precision binary64 (* r r))
double code(double r) {
	return r * r;
}
real(8) function code(r)
    real(8), intent (in) :: r
    code = r * r
end function
public static double code(double r) {
	return r * r;
}
def code(r):
	return r * r
function code(r)
	return Float64(r * r)
end
function tmp = code(r)
	tmp = r * r;
end
code[r_] := N[(r * r), $MachinePrecision]
\begin{array}{l}

\\
r \cdot r
\end{array}
Derivation
  1. Initial program 99.8%

    \[\mathsf{PI}\left(\right) \cdot {r}^{2} \]
  2. Add Preprocessing
  3. Applied rewrites59.2%

    \[\leadsto \color{blue}{r \cdot r} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 1 
(FPCore (r)
  :name "PI*r^2"
  :precision binary64
  :pre (and (<= 0.0 r) (<= r 1.79e+308))
  (* (PI) (pow r 2.0)))