
(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)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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)
(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}
Initial program 5.5%
lift-tan.f64N/A
tan-quotN/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lift-PI.f64N/A
cos-+PI/2-revN/A
sin-neg-revN/A
lower-sin.f64N/A
lift-neg.f64N/A
remove-double-negN/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
Applied rewrites99.7%
lift-/.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6499.8%
Applied rewrites99.8%
(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|
Initial program 5.5%
lift-tan.f64N/A
tan-quotN/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lift-PI.f64N/A
cos-+PI/2-revN/A
sin-neg-revN/A
lower-sin.f64N/A
lift-neg.f64N/A
remove-double-negN/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
Applied rewrites99.7%
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f6499.7%
Applied rewrites99.7%
lift-*.f64N/A
*-rgt-identityN/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r/N/A
lift-sin.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift-cos.f64N/A
tan-quotN/A
lift-tan.f64N/A
metadata-evalN/A
rem-exp-logN/A
lift-log.f64N/A
exp-fabsN/A
lift-log.f64N/A
rem-exp-logN/A
fabs-divN/A
lift-/.f64N/A
lower-fabs.f6450.2%
lift-/.f64N/A
lift-tan.f64N/A
tan-+PI/2-revN/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
lift-*.f64N/A
Applied rewrites7.5%
(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)
Initial program 5.5%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-neg.f64N/A
remove-double-neg5.5%
Applied rewrites5.5%
(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)
Initial program 5.5%
lift-tan.f64N/A
tan-+PI-revN/A
lower-tan.f64N/A
lift-PI.f64N/A
+-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
associate-+r-N/A
+-commutativeN/A
lower--.f64N/A
lift-*.f64N/A
distribute-lft1-inN/A
lower-*.f64N/A
metadata-evalN/A
lift-neg.f64N/A
remove-double-neg5.4%
Applied rewrites5.4%
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))))