(/ 1 (* z0 z0))

Percentage Accurate: 99.3% → 100.0%
Time: 981.0ms
Alternatives: 4
Speedup: 0.9×

Specification

?
\[\frac{1}{z0 \cdot z0} \]
(FPCore (z0)
  :precision binary64
  (/ 1.0 (* z0 z0)))
double code(double z0) {
	return 1.0 / (z0 * z0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = 1.0d0 / (z0 * z0)
end function
public static double code(double z0) {
	return 1.0 / (z0 * z0);
}
def code(z0):
	return 1.0 / (z0 * z0)
function code(z0)
	return Float64(1.0 / Float64(z0 * z0))
end
function tmp = code(z0)
	tmp = 1.0 / (z0 * z0);
end
code[z0_] := N[(1.0 / N[(z0 * z0), $MachinePrecision]), $MachinePrecision]
\frac{1}{z0 \cdot z0}

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

\[\frac{1}{z0 \cdot z0} \]
(FPCore (z0)
  :precision binary64
  (/ 1.0 (* z0 z0)))
double code(double z0) {
	return 1.0 / (z0 * z0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = 1.0d0 / (z0 * z0)
end function
public static double code(double z0) {
	return 1.0 / (z0 * z0);
}
def code(z0):
	return 1.0 / (z0 * z0)
function code(z0)
	return Float64(1.0 / Float64(z0 * z0))
end
function tmp = code(z0)
	tmp = 1.0 / (z0 * z0);
end
code[z0_] := N[(1.0 / N[(z0 * z0), $MachinePrecision]), $MachinePrecision]
\frac{1}{z0 \cdot z0}

Alternative 1: 100.0% accurate, 0.2× speedup?

\[{z0}^{-2} \]
(FPCore (z0)
  :precision binary64
  (pow z0 -2.0))
double code(double z0) {
	return pow(z0, -2.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = z0 ** (-2.0d0)
end function
public static double code(double z0) {
	return Math.pow(z0, -2.0);
}
def code(z0):
	return math.pow(z0, -2.0)
function code(z0)
	return z0 ^ -2.0
end
function tmp = code(z0)
	tmp = z0 ^ -2.0;
end
code[z0_] := N[Power[z0, -2.0], $MachinePrecision]
{z0}^{-2}
Derivation
  1. Initial program 99.3%

    \[\frac{1}{z0 \cdot z0} \]
  2. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{z0 \cdot z0}} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{1}{\color{blue}{z0 \cdot z0}} \]
    3. pow2N/A

      \[\leadsto \frac{1}{\color{blue}{{z0}^{2}}} \]
    4. pow-flipN/A

      \[\leadsto \color{blue}{{z0}^{\left(\mathsf{neg}\left(2\right)\right)}} \]
    5. lower-pow.f64N/A

      \[\leadsto \color{blue}{{z0}^{\left(\mathsf{neg}\left(2\right)\right)}} \]
    6. metadata-eval100.0%

      \[\leadsto {z0}^{\color{blue}{-2}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{{z0}^{-2}} \]
  4. Add Preprocessing

Alternative 2: 99.8% accurate, 0.7× speedup?

\[\frac{\frac{1}{z0}}{z0} \]
(FPCore (z0)
  :precision binary64
  (/ (/ 1.0 z0) z0))
double code(double z0) {
	return (1.0 / z0) / z0;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = (1.0d0 / z0) / z0
end function
public static double code(double z0) {
	return (1.0 / z0) / z0;
}
def code(z0):
	return (1.0 / z0) / z0
function code(z0)
	return Float64(Float64(1.0 / z0) / z0)
end
function tmp = code(z0)
	tmp = (1.0 / z0) / z0;
end
code[z0_] := N[(N[(1.0 / z0), $MachinePrecision] / z0), $MachinePrecision]
\frac{\frac{1}{z0}}{z0}
Derivation
  1. Initial program 99.3%

    \[\frac{1}{z0 \cdot z0} \]
  2. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{z0 \cdot z0}} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{1}{\color{blue}{z0 \cdot z0}} \]
    3. associate-/r*N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{z0}}{z0}} \]
    4. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{z0}}{z0}} \]
    5. lower-/.f6499.8%

      \[\leadsto \frac{\color{blue}{\frac{1}{z0}}}{z0} \]
  3. Applied rewrites99.8%

    \[\leadsto \color{blue}{\frac{\frac{1}{z0}}{z0}} \]
  4. Add Preprocessing

Alternative 3: 99.3% accurate, 0.9× speedup?

\[\frac{2}{\left(z0 + z0\right) \cdot z0} \]
(FPCore (z0)
  :precision binary64
  (/ 2.0 (* (+ z0 z0) z0)))
double code(double z0) {
	return 2.0 / ((z0 + z0) * z0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = 2.0d0 / ((z0 + z0) * z0)
end function
public static double code(double z0) {
	return 2.0 / ((z0 + z0) * z0);
}
def code(z0):
	return 2.0 / ((z0 + z0) * z0)
function code(z0)
	return Float64(2.0 / Float64(Float64(z0 + z0) * z0))
end
function tmp = code(z0)
	tmp = 2.0 / ((z0 + z0) * z0);
end
code[z0_] := N[(2.0 / N[(N[(z0 + z0), $MachinePrecision] * z0), $MachinePrecision]), $MachinePrecision]
\frac{2}{\left(z0 + z0\right) \cdot z0}
Derivation
  1. Initial program 99.3%

    \[\frac{1}{z0 \cdot z0} \]
  2. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{z0 \cdot z0}} \]
    2. mult-flipN/A

      \[\leadsto \color{blue}{1 \cdot \frac{1}{z0 \cdot z0}} \]
    3. metadata-evalN/A

      \[\leadsto \color{blue}{\frac{2}{2}} \cdot \frac{1}{z0 \cdot z0} \]
    4. frac-timesN/A

      \[\leadsto \color{blue}{\frac{2 \cdot 1}{2 \cdot \left(z0 \cdot z0\right)}} \]
    5. metadata-evalN/A

      \[\leadsto \frac{\color{blue}{2}}{2 \cdot \left(z0 \cdot z0\right)} \]
    6. lower-/.f64N/A

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

      \[\leadsto \frac{2}{2 \cdot \color{blue}{\left(z0 \cdot z0\right)}} \]
    8. associate-*r*N/A

      \[\leadsto \frac{2}{\color{blue}{\left(2 \cdot z0\right) \cdot z0}} \]
    9. lower-*.f64N/A

      \[\leadsto \frac{2}{\color{blue}{\left(2 \cdot z0\right) \cdot z0}} \]
    10. count-2-revN/A

      \[\leadsto \frac{2}{\color{blue}{\left(z0 + z0\right)} \cdot z0} \]
    11. lower-+.f6499.3%

      \[\leadsto \frac{2}{\color{blue}{\left(z0 + z0\right)} \cdot z0} \]
  3. Applied rewrites99.3%

    \[\leadsto \color{blue}{\frac{2}{\left(z0 + z0\right) \cdot z0}} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025250 
(FPCore (z0)
  :name "(/ 1 (* z0 z0))"
  :precision binary64
  (/ 1.0 (* z0 z0)))