
(FPCore (z0 z1 z2) :precision binary64 (/ z0 (* (tan z1) z2)))
double code(double z0, double z1, double z2) {
return z0 / (tan(z1) * z2);
}
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, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
code = z0 / (tan(z1) * z2)
end function
public static double code(double z0, double z1, double z2) {
return z0 / (Math.tan(z1) * z2);
}
def code(z0, z1, z2): return z0 / (math.tan(z1) * z2)
function code(z0, z1, z2) return Float64(z0 / Float64(tan(z1) * z2)) end
function tmp = code(z0, z1, z2) tmp = z0 / (tan(z1) * z2); end
code[z0_, z1_, z2_] := N[(z0 / N[(N[Tan[z1], $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]
\frac{z0}{\tan z1 \cdot z2}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z0 z1 z2) :precision binary64 (/ z0 (* (tan z1) z2)))
double code(double z0, double z1, double z2) {
return z0 / (tan(z1) * z2);
}
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, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
code = z0 / (tan(z1) * z2)
end function
public static double code(double z0, double z1, double z2) {
return z0 / (Math.tan(z1) * z2);
}
def code(z0, z1, z2): return z0 / (math.tan(z1) * z2)
function code(z0, z1, z2) return Float64(z0 / Float64(tan(z1) * z2)) end
function tmp = code(z0, z1, z2) tmp = z0 / (tan(z1) * z2); end
code[z0_, z1_, z2_] := N[(z0 / N[(N[Tan[z1], $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]
\frac{z0}{\tan z1 \cdot z2}
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (tan (fabs z1))))
(*
(copysign 1 z1)
(*
(copysign 1 z2)
(if (<=
(* t_0 (fabs z2))
80960901/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784)
(/ (/ z0 (fabs z2)) t_0)
(* (/ z0 (* (sin (fabs z1)) (fabs z2))) (cos (fabs z1))))))))double code(double z0, double z1, double z2) {
double t_0 = tan(fabs(z1));
double tmp;
if ((t_0 * fabs(z2)) <= 4e-316) {
tmp = (z0 / fabs(z2)) / t_0;
} else {
tmp = (z0 / (sin(fabs(z1)) * fabs(z2))) * cos(fabs(z1));
}
return copysign(1.0, z1) * (copysign(1.0, z2) * tmp);
}
public static double code(double z0, double z1, double z2) {
double t_0 = Math.tan(Math.abs(z1));
double tmp;
if ((t_0 * Math.abs(z2)) <= 4e-316) {
tmp = (z0 / Math.abs(z2)) / t_0;
} else {
tmp = (z0 / (Math.sin(Math.abs(z1)) * Math.abs(z2))) * Math.cos(Math.abs(z1));
}
return Math.copySign(1.0, z1) * (Math.copySign(1.0, z2) * tmp);
}
def code(z0, z1, z2): t_0 = math.tan(math.fabs(z1)) tmp = 0 if (t_0 * math.fabs(z2)) <= 4e-316: tmp = (z0 / math.fabs(z2)) / t_0 else: tmp = (z0 / (math.sin(math.fabs(z1)) * math.fabs(z2))) * math.cos(math.fabs(z1)) return math.copysign(1.0, z1) * (math.copysign(1.0, z2) * tmp)
function code(z0, z1, z2) t_0 = tan(abs(z1)) tmp = 0.0 if (Float64(t_0 * abs(z2)) <= 4e-316) tmp = Float64(Float64(z0 / abs(z2)) / t_0); else tmp = Float64(Float64(z0 / Float64(sin(abs(z1)) * abs(z2))) * cos(abs(z1))); end return Float64(copysign(1.0, z1) * Float64(copysign(1.0, z2) * tmp)) end
function tmp_2 = code(z0, z1, z2) t_0 = tan(abs(z1)); tmp = 0.0; if ((t_0 * abs(z2)) <= 4e-316) tmp = (z0 / abs(z2)) / t_0; else tmp = (z0 / (sin(abs(z1)) * abs(z2))) * cos(abs(z1)); end tmp_2 = (sign(z1) * abs(1.0)) * ((sign(z2) * abs(1.0)) * tmp); end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[Tan[N[Abs[z1], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[z1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[z2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$0 * N[Abs[z2], $MachinePrecision]), $MachinePrecision], 80960901/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784], N[(N[(z0 / N[Abs[z2], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(z0 / N[(N[Sin[N[Abs[z1], $MachinePrecision]], $MachinePrecision] * N[Abs[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[Abs[z1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \tan \left(\left|z1\right|\right)\\
\mathsf{copysign}\left(1, z1\right) \cdot \left(\mathsf{copysign}\left(1, z2\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \cdot \left|z2\right| \leq \frac{80960901}{202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784}:\\
\;\;\;\;\frac{\frac{z0}{\left|z2\right|}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{z0}{\sin \left(\left|z1\right|\right) \cdot \left|z2\right|} \cdot \cos \left(\left|z1\right|\right)\\
\end{array}\right)
\end{array}
if (*.f64 (tan.f64 z1) z2) < 3.9999999840454223e-316Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6496.1%
Applied rewrites96.1%
if 3.9999999840454223e-316 < (*.f64 (tan.f64 z1) z2) Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lift-tan.f64N/A
tan-quotN/A
associate-/r/N/A
lower-*.f64N/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6495.7%
Applied rewrites95.7%
(FPCore (z0 z1 z2) :precision binary64 (* (copysign 1 z2) (if (<= (fabs z2) 900) (/ (/ z0 (fabs z2)) (tan z1)) (/ z0 (* (tan z1) (fabs z2))))))
double code(double z0, double z1, double z2) {
double tmp;
if (fabs(z2) <= 900.0) {
tmp = (z0 / fabs(z2)) / tan(z1);
} else {
tmp = z0 / (tan(z1) * fabs(z2));
}
return copysign(1.0, z2) * tmp;
}
public static double code(double z0, double z1, double z2) {
double tmp;
if (Math.abs(z2) <= 900.0) {
tmp = (z0 / Math.abs(z2)) / Math.tan(z1);
} else {
tmp = z0 / (Math.tan(z1) * Math.abs(z2));
}
return Math.copySign(1.0, z2) * tmp;
}
def code(z0, z1, z2): tmp = 0 if math.fabs(z2) <= 900.0: tmp = (z0 / math.fabs(z2)) / math.tan(z1) else: tmp = z0 / (math.tan(z1) * math.fabs(z2)) return math.copysign(1.0, z2) * tmp
function code(z0, z1, z2) tmp = 0.0 if (abs(z2) <= 900.0) tmp = Float64(Float64(z0 / abs(z2)) / tan(z1)); else tmp = Float64(z0 / Float64(tan(z1) * abs(z2))); end return Float64(copysign(1.0, z2) * tmp) end
function tmp_2 = code(z0, z1, z2) tmp = 0.0; if (abs(z2) <= 900.0) tmp = (z0 / abs(z2)) / tan(z1); else tmp = z0 / (tan(z1) * abs(z2)); end tmp_2 = (sign(z2) * abs(1.0)) * tmp; end
code[z0_, z1_, z2_] := N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[z2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[z2], $MachinePrecision], 900], N[(N[(z0 / N[Abs[z2], $MachinePrecision]), $MachinePrecision] / N[Tan[z1], $MachinePrecision]), $MachinePrecision], N[(z0 / N[(N[Tan[z1], $MachinePrecision] * N[Abs[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, z2\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|z2\right| \leq 900:\\
\;\;\;\;\frac{\frac{z0}{\left|z2\right|}}{\tan z1}\\
\mathbf{else}:\\
\;\;\;\;\frac{z0}{\tan z1 \cdot \left|z2\right|}\\
\end{array}
if z2 < 900Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6496.1%
Applied rewrites96.1%
if 900 < z2 Initial program 95.8%
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1 z2)
:name "(/ z0 (* (tan z1) z2))"
:precision binary64
(/ z0 (* (tan z1) z2)))