(- PI (* (* (* z0 z0) PI) (* (* PI PI) 8333333333333333/50000000000000000)))

Percentage Accurate: 99.6% → 99.9%
Time: 1.2s
Alternatives: 2
Speedup: 1.5×

Specification

?
\[\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \left(\left(\pi \cdot \pi\right) \cdot 0.16666666666666666\right) \]
(FPCore (z0)
  :precision binary64
  (- PI (* (* (* z0 z0) PI) (* (* PI PI) 0.16666666666666666))))
double code(double z0) {
	return ((double) M_PI) - (((z0 * z0) * ((double) M_PI)) * ((((double) M_PI) * ((double) M_PI)) * 0.16666666666666666));
}
public static double code(double z0) {
	return Math.PI - (((z0 * z0) * Math.PI) * ((Math.PI * Math.PI) * 0.16666666666666666));
}
def code(z0):
	return math.pi - (((z0 * z0) * math.pi) * ((math.pi * math.pi) * 0.16666666666666666))
function code(z0)
	return Float64(pi - Float64(Float64(Float64(z0 * z0) * pi) * Float64(Float64(pi * pi) * 0.16666666666666666)))
end
function tmp = code(z0)
	tmp = pi - (((z0 * z0) * pi) * ((pi * pi) * 0.16666666666666666));
end
code[z0_] := N[(Pi - N[(N[(N[(z0 * z0), $MachinePrecision] * Pi), $MachinePrecision] * N[(N[(Pi * Pi), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \left(\left(\pi \cdot \pi\right) \cdot 0.16666666666666666\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 2 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.6% accurate, 1.0× speedup?

\[\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \left(\left(\pi \cdot \pi\right) \cdot 0.16666666666666666\right) \]
(FPCore (z0)
  :precision binary64
  (- PI (* (* (* z0 z0) PI) (* (* PI PI) 0.16666666666666666))))
double code(double z0) {
	return ((double) M_PI) - (((z0 * z0) * ((double) M_PI)) * ((((double) M_PI) * ((double) M_PI)) * 0.16666666666666666));
}
public static double code(double z0) {
	return Math.PI - (((z0 * z0) * Math.PI) * ((Math.PI * Math.PI) * 0.16666666666666666));
}
def code(z0):
	return math.pi - (((z0 * z0) * math.pi) * ((math.pi * math.pi) * 0.16666666666666666))
function code(z0)
	return Float64(pi - Float64(Float64(Float64(z0 * z0) * pi) * Float64(Float64(pi * pi) * 0.16666666666666666)))
end
function tmp = code(z0)
	tmp = pi - (((z0 * z0) * pi) * ((pi * pi) * 0.16666666666666666));
end
code[z0_] := N[(Pi - N[(N[(N[(z0 * z0), $MachinePrecision] * Pi), $MachinePrecision] * N[(N[(Pi * Pi), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \left(\left(\pi \cdot \pi\right) \cdot 0.16666666666666666\right)

Alternative 1: 99.9% accurate, 1.5× speedup?

\[\left(\left(z0 \cdot z0\right) \cdot \pi - 1.909859317102744\right) \cdot -1.6449340668482264 \]
(FPCore (z0)
  :precision binary64
  (* (- (* (* z0 z0) PI) 1.909859317102744) -1.6449340668482264))
double code(double z0) {
	return (((z0 * z0) * ((double) M_PI)) - 1.909859317102744) * -1.6449340668482264;
}
public static double code(double z0) {
	return (((z0 * z0) * Math.PI) - 1.909859317102744) * -1.6449340668482264;
}
def code(z0):
	return (((z0 * z0) * math.pi) - 1.909859317102744) * -1.6449340668482264
function code(z0)
	return Float64(Float64(Float64(Float64(z0 * z0) * pi) - 1.909859317102744) * -1.6449340668482264)
end
function tmp = code(z0)
	tmp = (((z0 * z0) * pi) - 1.909859317102744) * -1.6449340668482264;
end
code[z0_] := N[(N[(N[(N[(z0 * z0), $MachinePrecision] * Pi), $MachinePrecision] - 1.909859317102744), $MachinePrecision] * -1.6449340668482264), $MachinePrecision]
\left(\left(z0 \cdot z0\right) \cdot \pi - 1.909859317102744\right) \cdot -1.6449340668482264
Derivation
  1. Initial program 99.6%

    \[\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \left(\left(\pi \cdot \pi\right) \cdot 0.16666666666666666\right) \]
  2. Evaluated real constant99.9%

    \[\leadsto \pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \color{blue}{1.6449340668482264} \]
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \frac{7408124450506707}{4503599627370496}} \]
    2. lift-*.f64N/A

      \[\leadsto \pi - \color{blue}{\left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \frac{7408124450506707}{4503599627370496}} \]
    3. fp-cancel-sub-sign-invN/A

      \[\leadsto \color{blue}{\pi + \left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}} \]
    4. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496} + \pi} \]
    5. sum-to-multN/A

      \[\leadsto \color{blue}{\left(1 + \frac{\pi}{\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right)} \]
    6. lower-unsound-*.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\pi}{\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right)} \]
    7. lower-unsound-+.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\pi}{\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}}\right)} \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    8. lower-unsound-/.f64N/A

      \[\leadsto \left(1 + \color{blue}{\frac{\pi}{\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    9. *-commutativeN/A

      \[\leadsto \left(1 + \frac{\pi}{\color{blue}{\frac{7408124450506707}{4503599627370496} \cdot \left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    10. distribute-rgt-neg-inN/A

      \[\leadsto \left(1 + \frac{\pi}{\color{blue}{\mathsf{neg}\left(\frac{7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    11. distribute-lft-neg-inN/A

      \[\leadsto \left(1 + \frac{\pi}{\color{blue}{\left(\mathsf{neg}\left(\frac{7408124450506707}{4503599627370496}\right)\right) \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    12. lower-*.f64N/A

      \[\leadsto \left(1 + \frac{\pi}{\color{blue}{\left(\mathsf{neg}\left(\frac{7408124450506707}{4503599627370496}\right)\right) \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    13. metadata-evalN/A

      \[\leadsto \left(1 + \frac{\pi}{\color{blue}{\frac{-7408124450506707}{4503599627370496}} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \left(\left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{7408124450506707}{4503599627370496}\right) \]
    14. *-commutativeN/A

      \[\leadsto \left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \color{blue}{\left(\frac{7408124450506707}{4503599627370496} \cdot \left(\mathsf{neg}\left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)\right)} \]
    15. distribute-rgt-neg-inN/A

      \[\leadsto \left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)\right)} \]
    16. distribute-lft-neg-inN/A

      \[\leadsto \left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\frac{7408124450506707}{4503599627370496}\right)\right) \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)} \]
    17. lower-*.f64N/A

      \[\leadsto \left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\frac{7408124450506707}{4503599627370496}\right)\right) \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)} \]
  4. Applied rewrites74.8%

    \[\leadsto \color{blue}{\left(1 + \frac{\pi}{-1.6449340668482264 \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \left(-1.6449340668482264 \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \left(\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \color{blue}{\left(\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right)} \]
    3. *-commutativeN/A

      \[\leadsto \left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \color{blue}{\left(\left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \frac{-7408124450506707}{4503599627370496}\right)} \]
    4. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\left(1 + \frac{\pi}{\frac{-7408124450506707}{4503599627370496} \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)}\right) \cdot \left(\left(z0 \cdot z0\right) \cdot \pi\right)\right) \cdot \frac{-7408124450506707}{4503599627370496}} \]
  6. Applied rewrites99.9%

    \[\leadsto \color{blue}{\left(\left(z0 \cdot z0\right) \cdot \pi - \pi \cdot 0.6079271018540267\right) \cdot -1.6449340668482264} \]
  7. Evaluated real constant99.9%

    \[\leadsto \left(\left(z0 \cdot z0\right) \cdot \pi - \color{blue}{1.909859317102744}\right) \cdot -1.6449340668482264 \]
  8. Add Preprocessing

Alternative 2: 50.6% accurate, 29.0× speedup?

\[\pi \]
(FPCore (z0)
  :precision binary64
  PI)
double code(double z0) {
	return (double) M_PI;
}
public static double code(double z0) {
	return Math.PI;
}
def code(z0):
	return math.pi
function code(z0)
	return pi
end
function tmp = code(z0)
	tmp = pi;
end
code[z0_] := Pi
\pi
Derivation
  1. Initial program 99.6%

    \[\pi - \left(\left(z0 \cdot z0\right) \cdot \pi\right) \cdot \left(\left(\pi \cdot \pi\right) \cdot 0.16666666666666666\right) \]
  2. Taylor expanded in z0 around 0

    \[\leadsto \color{blue}{\pi} \]
  3. Step-by-step derivation
    1. lower-PI.f6450.6%

      \[\leadsto \pi \]
  4. Applied rewrites50.6%

    \[\leadsto \color{blue}{\pi} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025250 
(FPCore (z0)
  :name "(- PI (* (* (* z0 z0) PI) (* (* PI PI) 8333333333333333/50000000000000000)))"
  :precision binary64
  (- PI (* (* (* z0 z0) PI) (* (* PI PI) 0.16666666666666666))))