(tan (+ (- z0) (* 1/2 PI)))

Percentage Accurate: 5.5% → 99.8%
Time: 9.8s
Alternatives: 4
Speedup: 1.0×

Specification

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

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

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\frac{1}{\tan z0} \]
(FPCore (z0)
  :precision binary64
  (/ 1 (tan z0)))
double code(double z0) {
	return 1.0 / tan(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 / tan(z0)
end function
public static double code(double z0) {
	return 1.0 / Math.tan(z0);
}
def code(z0):
	return 1.0 / math.tan(z0)
function code(z0)
	return Float64(1.0 / tan(z0))
end
function tmp = code(z0)
	tmp = 1.0 / tan(z0);
end
code[z0_] := N[(1 / N[Tan[z0], $MachinePrecision]), $MachinePrecision]
\frac{1}{\tan z0}
Derivation
  1. Initial program 5.5%

    \[\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) \]
  2. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)} \]
    2. tan-quotN/A

      \[\leadsto \color{blue}{\frac{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}{\cos \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    3. div-flipN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}}} \]
    4. lower-unsound-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}}} \]
    5. lower-unsound-/.f64N/A

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

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

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    8. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    10. mult-flipN/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \color{blue}{\frac{\pi}{2}}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    11. lift-PI.f64N/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    12. cos-+PI/2-revN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{neg}\left(\sin \left(-z0\right)\right)}}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    13. sin-neg-revN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sin \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)}}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    14. lower-sin.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sin \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)}}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    15. lift-neg.f64N/A

      \[\leadsto \frac{1}{\frac{\sin \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    16. remove-double-negN/A

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\frac{\sin z0}{\cos z0}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sin z0}}{\cos z0}} \]
    3. lift-cos.f64N/A

      \[\leadsto \frac{1}{\frac{\sin z0}{\color{blue}{\cos z0}}} \]
    4. quot-tanN/A

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

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

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

Alternative 2: 7.5% accurate, 1.0× speedup?

\[\left|\tan \left(\pi \cdot \frac{1}{2} - z0\right)\right| \]
(FPCore (z0)
  :precision binary64
  (fabs (tan (- (* PI 1/2) z0))))
double code(double z0) {
	return fabs(tan(((((double) M_PI) * 0.5) - z0)));
}
public static double code(double z0) {
	return Math.abs(Math.tan(((Math.PI * 0.5) - z0)));
}
def code(z0):
	return math.fabs(math.tan(((math.pi * 0.5) - z0)))
function code(z0)
	return abs(tan(Float64(Float64(pi * 0.5) - z0)))
end
function tmp = code(z0)
	tmp = abs(tan(((pi * 0.5) - z0)));
end
code[z0_] := N[Abs[N[Tan[N[(N[(Pi * 1/2), $MachinePrecision] - z0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\left|\tan \left(\pi \cdot \frac{1}{2} - z0\right)\right|
Derivation
  1. Initial program 5.5%

    \[\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) \]
  2. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)} \]
    2. tan-quotN/A

      \[\leadsto \color{blue}{\frac{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}{\cos \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    3. div-flipN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}}} \]
    4. lower-unsound-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}}} \]
    5. lower-unsound-/.f64N/A

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

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

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    8. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    10. mult-flipN/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \color{blue}{\frac{\pi}{2}}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    11. lift-PI.f64N/A

      \[\leadsto \frac{1}{\frac{\cos \left(\left(-z0\right) + \frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    12. cos-+PI/2-revN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{neg}\left(\sin \left(-z0\right)\right)}}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    13. sin-neg-revN/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sin \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)}}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    14. lower-sin.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sin \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)}}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    15. lift-neg.f64N/A

      \[\leadsto \frac{1}{\frac{\sin \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right)}{\sin \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}} \]
    16. remove-double-negN/A

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\frac{\sin z0}{\cos z0}}} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin z0} \cdot \cos z0} \]
    5. lower-/.f6499.7%

      \[\leadsto \color{blue}{\frac{1}{\sin z0}} \cdot \cos z0 \]
  5. Applied rewrites99.7%

    \[\leadsto \color{blue}{\frac{1}{\sin z0} \cdot \cos z0} \]
  6. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\sin z0} \cdot \cos z0} \]
    2. *-rgt-identityN/A

      \[\leadsto \frac{1}{\sin z0} \cdot \color{blue}{\left(\cos z0 \cdot 1\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{1}{\sin z0} \cdot \color{blue}{\left(\cos z0 \cdot 1\right)} \]
    4. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\sin z0}} \cdot \left(\cos z0 \cdot 1\right) \]
    5. associate-/r/N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sin z0}{\cos z0 \cdot 1}}} \]
    6. lift-sin.f64N/A

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

      \[\leadsto \frac{1}{\frac{\sin z0}{\color{blue}{\cos z0 \cdot 1}}} \]
    8. *-rgt-identityN/A

      \[\leadsto \frac{1}{\frac{\sin z0}{\color{blue}{\cos z0}}} \]
    9. lift-cos.f64N/A

      \[\leadsto \frac{1}{\frac{\sin z0}{\color{blue}{\cos z0}}} \]
    10. tan-quotN/A

      \[\leadsto \frac{1}{\color{blue}{\tan z0}} \]
    11. lift-tan.f64N/A

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

      \[\leadsto \frac{\color{blue}{\left|1\right|}}{\tan z0} \]
    13. rem-exp-logN/A

      \[\leadsto \frac{\left|1\right|}{\color{blue}{e^{\log \tan z0}}} \]
    14. lift-log.f64N/A

      \[\leadsto \frac{\left|1\right|}{e^{\color{blue}{\log \tan z0}}} \]
    15. exp-fabsN/A

      \[\leadsto \frac{\left|1\right|}{\color{blue}{\left|e^{\log \tan z0}\right|}} \]
    16. lift-log.f64N/A

      \[\leadsto \frac{\left|1\right|}{\left|e^{\color{blue}{\log \tan z0}}\right|} \]
    17. rem-exp-logN/A

      \[\leadsto \frac{\left|1\right|}{\left|\color{blue}{\tan z0}\right|} \]
    18. fabs-divN/A

      \[\leadsto \color{blue}{\left|\frac{1}{\tan z0}\right|} \]
    19. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{1}{\tan z0}}\right| \]
    20. lower-fabs.f6450.2%

      \[\leadsto \color{blue}{\left|\frac{1}{\tan z0}\right|} \]
    21. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{1}{\tan z0}}\right| \]
    22. lift-tan.f64N/A

      \[\leadsto \left|\frac{1}{\color{blue}{\tan z0}}\right| \]
    23. tan-+PI/2-revN/A

      \[\leadsto \left|\color{blue}{\tan \left(\left(\mathsf{neg}\left(z0\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)}\right| \]
    24. lift-PI.f64N/A

      \[\leadsto \left|\tan \left(\left(\mathsf{neg}\left(z0\right)\right) + \frac{\color{blue}{\pi}}{2}\right)\right| \]
    25. mult-flipN/A

      \[\leadsto \left|\tan \left(\left(\mathsf{neg}\left(z0\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right)\right| \]
    26. metadata-evalN/A

      \[\leadsto \left|\tan \left(\left(\mathsf{neg}\left(z0\right)\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right)\right| \]
    27. lift-*.f64N/A

      \[\leadsto \left|\tan \left(\left(\mathsf{neg}\left(z0\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right)\right| \]
  7. Applied rewrites7.5%

    \[\leadsto \color{blue}{\left|\tan \left(\pi \cdot \frac{1}{2} - z0\right)\right|} \]
  8. Add Preprocessing

Alternative 3: 5.5% accurate, 1.0× speedup?

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

    \[\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \tan \color{blue}{\left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)} \]
    2. +-commutativeN/A

      \[\leadsto \tan \color{blue}{\left(\frac{1}{2} \cdot \pi + \left(-z0\right)\right)} \]
    3. add-flipN/A

      \[\leadsto \tan \color{blue}{\left(\frac{1}{2} \cdot \pi - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right)} \]
    4. lower--.f64N/A

      \[\leadsto \tan \color{blue}{\left(\frac{1}{2} \cdot \pi - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right)} \]
    5. lift-*.f64N/A

      \[\leadsto \tan \left(\color{blue}{\frac{1}{2} \cdot \pi} - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \tan \left(\color{blue}{\pi \cdot \frac{1}{2}} - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right) \]
    7. lower-*.f64N/A

      \[\leadsto \tan \left(\color{blue}{\pi \cdot \frac{1}{2}} - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right) \]
    8. lift-neg.f64N/A

      \[\leadsto \tan \left(\pi \cdot \frac{1}{2} - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right)\right) \]
    9. remove-double-neg5.5%

      \[\leadsto \tan \left(\pi \cdot \frac{1}{2} - \color{blue}{z0}\right) \]
  3. Applied rewrites5.5%

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

Alternative 4: 5.4% accurate, 1.0× speedup?

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

    \[\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) \]
  2. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)} \]
    2. tan-+PI-revN/A

      \[\leadsto \color{blue}{\tan \left(\left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) + \mathsf{PI}\left(\right)\right)} \]
    3. lower-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(\left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) + \mathsf{PI}\left(\right)\right)} \]
    4. lift-PI.f64N/A

      \[\leadsto \tan \left(\left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right) + \color{blue}{\pi}\right) \]
    5. +-commutativeN/A

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

      \[\leadsto \tan \left(\pi + \color{blue}{\left(\left(-z0\right) + \frac{1}{2} \cdot \pi\right)}\right) \]
    7. +-commutativeN/A

      \[\leadsto \tan \left(\pi + \color{blue}{\left(\frac{1}{2} \cdot \pi + \left(-z0\right)\right)}\right) \]
    8. add-flipN/A

      \[\leadsto \tan \left(\pi + \color{blue}{\left(\frac{1}{2} \cdot \pi - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right)}\right) \]
    9. associate-+r-N/A

      \[\leadsto \tan \color{blue}{\left(\left(\pi + \frac{1}{2} \cdot \pi\right) - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right)} \]
    10. +-commutativeN/A

      \[\leadsto \tan \left(\color{blue}{\left(\frac{1}{2} \cdot \pi + \pi\right)} - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right) \]
    11. lower--.f64N/A

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

      \[\leadsto \tan \left(\left(\color{blue}{\frac{1}{2} \cdot \pi} + \pi\right) - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right) \]
    13. distribute-lft1-inN/A

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

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

      \[\leadsto \tan \left(\color{blue}{\frac{3}{2}} \cdot \pi - \left(\mathsf{neg}\left(\left(-z0\right)\right)\right)\right) \]
    16. lift-neg.f64N/A

      \[\leadsto \tan \left(\frac{3}{2} \cdot \pi - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right)\right) \]
    17. remove-double-neg5.4%

      \[\leadsto \tan \left(\frac{3}{2} \cdot \pi - \color{blue}{z0}\right) \]
  3. Applied rewrites5.4%

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

Reproduce

?
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0)
  :name "(tan (+ (- z0) (* 1/2 PI)))"
  :precision binary64
  (tan (+ (- z0) (* 1/2 PI))))