
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2 49/5) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
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(v, h)
use fmin_fmax_functions
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2 * 49/5), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot \frac{49}{5}\right) \cdot H}}\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2 49/5) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
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(v, h)
use fmin_fmax_functions
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2 * 49/5), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot \frac{49}{5}\right) \cdot H}}\right)
(FPCore (v H)
:precision binary64
(*
(copysign 1 v)
(if (<=
(fabs v)
380000000000000004904163926623671165493212962612946153153875573383667984952320421366390063104)
(atan (/ (fabs v) (sqrt (- (* (fabs v) (fabs v)) (* H 98/5)))))
(atan 1))))double code(double v, double H) {
double tmp;
if (fabs(v) <= 3.8e+92) {
tmp = atan((fabs(v) / sqrt(((fabs(v) * fabs(v)) - (H * 19.6)))));
} else {
tmp = atan(1.0);
}
return copysign(1.0, v) * tmp;
}
public static double code(double v, double H) {
double tmp;
if (Math.abs(v) <= 3.8e+92) {
tmp = Math.atan((Math.abs(v) / Math.sqrt(((Math.abs(v) * Math.abs(v)) - (H * 19.6)))));
} else {
tmp = Math.atan(1.0);
}
return Math.copySign(1.0, v) * tmp;
}
def code(v, H): tmp = 0 if math.fabs(v) <= 3.8e+92: tmp = math.atan((math.fabs(v) / math.sqrt(((math.fabs(v) * math.fabs(v)) - (H * 19.6))))) else: tmp = math.atan(1.0) return math.copysign(1.0, v) * tmp
function code(v, H) tmp = 0.0 if (abs(v) <= 3.8e+92) tmp = atan(Float64(abs(v) / sqrt(Float64(Float64(abs(v) * abs(v)) - Float64(H * 19.6))))); else tmp = atan(1.0); end return Float64(copysign(1.0, v) * tmp) end
function tmp_2 = code(v, H) tmp = 0.0; if (abs(v) <= 3.8e+92) tmp = atan((abs(v) / sqrt(((abs(v) * abs(v)) - (H * 19.6))))); else tmp = atan(1.0); end tmp_2 = (sign(v) * abs(1.0)) * tmp; end
code[v_, H_] := N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[v], $MachinePrecision], 380000000000000004904163926623671165493212962612946153153875573383667984952320421366390063104], N[ArcTan[N[(N[Abs[v], $MachinePrecision] / N[Sqrt[N[(N[(N[Abs[v], $MachinePrecision] * N[Abs[v], $MachinePrecision]), $MachinePrecision] - N[(H * 98/5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, v\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|v\right| \leq 380000000000000004904163926623671165493212962612946153153875573383667984952320421366390063104:\\
\;\;\;\;\tan^{-1} \left(\frac{\left|v\right|}{\sqrt{\left|v\right| \cdot \left|v\right| - H \cdot \frac{98}{5}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
if v < 3.8e92Initial program 67.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6467.2%
lift-*.f64N/A
metadata-eval67.2%
Applied rewrites67.2%
if 3.8e92 < v Initial program 67.2%
Taylor expanded in v around inf
Applied rewrites35.3%
(FPCore (v H)
:precision binary64
(let* ((t_0
(atan
(/
(fabs v)
(sqrt (- (* (fabs v) (fabs v)) (* (* 2 49/5) H)))))))
(*
(copysign 1 v)
(if (<= t_0 0)
(atan 1)
(if (<= t_0 3602879701896397/9007199254740992)
(atan (/ (fabs v) (sqrt (* -98/5 H))))
(atan 1))))))double code(double v, double H) {
double t_0 = atan((fabs(v) / sqrt(((fabs(v) * fabs(v)) - ((2.0 * 9.8) * H)))));
double tmp;
if (t_0 <= 0.0) {
tmp = atan(1.0);
} else if (t_0 <= 0.4) {
tmp = atan((fabs(v) / sqrt((-19.6 * H))));
} else {
tmp = atan(1.0);
}
return copysign(1.0, v) * tmp;
}
public static double code(double v, double H) {
double t_0 = Math.atan((Math.abs(v) / Math.sqrt(((Math.abs(v) * Math.abs(v)) - ((2.0 * 9.8) * H)))));
double tmp;
if (t_0 <= 0.0) {
tmp = Math.atan(1.0);
} else if (t_0 <= 0.4) {
tmp = Math.atan((Math.abs(v) / Math.sqrt((-19.6 * H))));
} else {
tmp = Math.atan(1.0);
}
return Math.copySign(1.0, v) * tmp;
}
def code(v, H): t_0 = math.atan((math.fabs(v) / math.sqrt(((math.fabs(v) * math.fabs(v)) - ((2.0 * 9.8) * H))))) tmp = 0 if t_0 <= 0.0: tmp = math.atan(1.0) elif t_0 <= 0.4: tmp = math.atan((math.fabs(v) / math.sqrt((-19.6 * H)))) else: tmp = math.atan(1.0) return math.copysign(1.0, v) * tmp
function code(v, H) t_0 = atan(Float64(abs(v) / sqrt(Float64(Float64(abs(v) * abs(v)) - Float64(Float64(2.0 * 9.8) * H))))) tmp = 0.0 if (t_0 <= 0.0) tmp = atan(1.0); elseif (t_0 <= 0.4) tmp = atan(Float64(abs(v) / sqrt(Float64(-19.6 * H)))); else tmp = atan(1.0); end return Float64(copysign(1.0, v) * tmp) end
function tmp_2 = code(v, H) t_0 = atan((abs(v) / sqrt(((abs(v) * abs(v)) - ((2.0 * 9.8) * H))))); tmp = 0.0; if (t_0 <= 0.0) tmp = atan(1.0); elseif (t_0 <= 0.4) tmp = atan((abs(v) / sqrt((-19.6 * H)))); else tmp = atan(1.0); end tmp_2 = (sign(v) * abs(1.0)) * tmp; end
code[v_, H_] := Block[{t$95$0 = N[ArcTan[N[(N[Abs[v], $MachinePrecision] / N[Sqrt[N[(N[(N[Abs[v], $MachinePrecision] * N[Abs[v], $MachinePrecision]), $MachinePrecision] - N[(N[(2 * 49/5), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$0, 0], N[ArcTan[1], $MachinePrecision], If[LessEqual[t$95$0, 3602879701896397/9007199254740992], N[ArcTan[N[(N[Abs[v], $MachinePrecision] / N[Sqrt[N[(-98/5 * H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1], $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{\left|v\right|}{\sqrt{\left|v\right| \cdot \left|v\right| - \left(2 \cdot \frac{49}{5}\right) \cdot H}}\right)\\
\mathsf{copysign}\left(1, v\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\tan^{-1} 1\\
\mathbf{elif}\;t\_0 \leq \frac{3602879701896397}{9007199254740992}:\\
\;\;\;\;\tan^{-1} \left(\frac{\left|v\right|}{\sqrt{\frac{-98}{5} \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) < 0.0 or 0.40000000000000002 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) Initial program 67.2%
Taylor expanded in v around inf
Applied rewrites35.3%
if 0.0 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) < 0.40000000000000002Initial program 67.2%
Taylor expanded in v around 0
lower-*.f6439.2%
Applied rewrites39.2%
(FPCore (v H) :precision binary64 (* (copysign 1 v) (atan 1)))
double code(double v, double H) {
return copysign(1.0, v) * atan(1.0);
}
public static double code(double v, double H) {
return Math.copySign(1.0, v) * Math.atan(1.0);
}
def code(v, H): return math.copysign(1.0, v) * math.atan(1.0)
function code(v, H) return Float64(copysign(1.0, v) * atan(1.0)) end
function tmp = code(v, H) tmp = (sign(v) * abs(1.0)) * atan(1.0); end
code[v_, H_] := N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[ArcTan[1], $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, v\right) \cdot \tan^{-1} 1
Initial program 67.2%
Taylor expanded in v around inf
Applied rewrites35.3%
(FPCore (v H) :precision binary64 (atan -1))
double code(double v, double H) {
return atan(-1.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(v, h)
use fmin_fmax_functions
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((-1.0d0))
end function
public static double code(double v, double H) {
return Math.atan(-1.0);
}
def code(v, H): return math.atan(-1.0)
function code(v, H) return atan(-1.0) end
function tmp = code(v, H) tmp = atan(-1.0); end
code[v_, H_] := N[ArcTan[-1], $MachinePrecision]
\tan^{-1} -1
Initial program 67.2%
Taylor expanded in v around -inf
Applied rewrites34.2%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2 49/5) H))))))