
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) 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.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) 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.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
v\_m = (fabs.f64 v)
v\_s = (copysign.f64 #s(literal 1 binary64) v)
(FPCore (v_s v_m H)
:precision binary64
(*
v_s
(if (<= v_m 5e+122)
(atan (/ v_m (sqrt (fma v_m v_m (* -19.6 H)))))
(atan 1.0))))v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
double tmp;
if (v_m <= 5e+122) {
tmp = atan((v_m / sqrt(fma(v_m, v_m, (-19.6 * H)))));
} else {
tmp = atan(1.0);
}
return v_s * tmp;
}
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, v_m, H) tmp = 0.0 if (v_m <= 5e+122) tmp = atan(Float64(v_m / sqrt(fma(v_m, v_m, Float64(-19.6 * H))))); else tmp = atan(1.0); end return Float64(v_s * tmp) end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := N[(v$95$s * If[LessEqual[v$95$m, 5e+122], N[ArcTan[N[(v$95$m / N[Sqrt[N[(v$95$m * v$95$m + N[(-19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \begin{array}{l}
\mathbf{if}\;v\_m \leq 5 \cdot 10^{+122}:\\
\;\;\;\;\tan^{-1} \left(\frac{v\_m}{\sqrt{\mathsf{fma}\left(v\_m, v\_m, -19.6 \cdot H\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < 4.99999999999999989e122Initial program 99.6%
lift-*.f64N/A
lift--.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6499.6
Applied rewrites99.6%
if 4.99999999999999989e122 < v Initial program 18.7%
Taylor expanded in v around inf
Applied rewrites99.5%
v\_m = (fabs.f64 v)
v\_s = (copysign.f64 #s(literal 1 binary64) v)
(FPCore (v_s v_m H)
:precision binary64
(let* ((t_0 (atan (/ v_m (fma (/ H v_m) -9.8 v_m))))
(t_1 (atan (/ v_m (sqrt (- (* v_m v_m) (* (* 2.0 9.8) H)))))))
(*
v_s
(if (<= t_1 0.0)
t_0
(if (<= t_1 4e-5)
(atan (* (sqrt (/ -0.05102040816326531 H)) v_m))
t_0)))))v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
double t_0 = atan((v_m / fma((H / v_m), -9.8, v_m)));
double t_1 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
double tmp;
if (t_1 <= 0.0) {
tmp = t_0;
} else if (t_1 <= 4e-5) {
tmp = atan((sqrt((-0.05102040816326531 / H)) * v_m));
} else {
tmp = t_0;
}
return v_s * tmp;
}
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, v_m, H) t_0 = atan(Float64(v_m / fma(Float64(H / v_m), -9.8, v_m))) t_1 = atan(Float64(v_m / sqrt(Float64(Float64(v_m * v_m) - Float64(Float64(2.0 * 9.8) * H))))) tmp = 0.0 if (t_1 <= 0.0) tmp = t_0; elseif (t_1 <= 4e-5) tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v_m)); else tmp = t_0; end return Float64(v_s * tmp) end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := Block[{t$95$0 = N[ArcTan[N[(v$95$m / N[(N[(H / v$95$m), $MachinePrecision] * -9.8 + v$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcTan[N[(v$95$m / N[Sqrt[N[(N[(v$95$m * v$95$m), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(v$95$s * If[LessEqual[t$95$1, 0.0], t$95$0, If[LessEqual[t$95$1, 4e-5], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v$95$m), $MachinePrecision]], $MachinePrecision], t$95$0]]), $MachinePrecision]]]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{v\_m}{\mathsf{fma}\left(\frac{H}{v\_m}, -9.8, v\_m\right)}\right)\\
t_1 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\
v\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\_m\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\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 4.00000000000000033e-5 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) Initial program 53.3%
Taylor expanded in H around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.0
Applied rewrites99.0%
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))))) < 4.00000000000000033e-5Initial program 99.5%
Taylor expanded in v around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
metadata-evalN/A
+-commutativeN/A
lower-atan.f64N/A
*-commutativeN/A
Applied rewrites99.4%
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
lower-sqrt.f64N/A
sqrt-divN/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6499.4
Applied rewrites99.4%
Taylor expanded in v around 0
lower-/.f6499.4
Applied rewrites99.4%
v\_m = (fabs.f64 v)
v\_s = (copysign.f64 #s(literal 1 binary64) v)
(FPCore (v_s v_m H)
:precision binary64
(let* ((t_0 (atan (/ v_m (sqrt (- (* v_m v_m) (* (* 2.0 9.8) H)))))))
(*
v_s
(if (<= t_0 0.0)
(atan 1.0)
(if (<= t_0 0.6)
(atan (* (sqrt (/ -0.05102040816326531 H)) v_m))
(atan (fma (/ H (* v_m v_m)) 9.8 1.0)))))))v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
double t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
double tmp;
if (t_0 <= 0.0) {
tmp = atan(1.0);
} else if (t_0 <= 0.6) {
tmp = atan((sqrt((-0.05102040816326531 / H)) * v_m));
} else {
tmp = atan(fma((H / (v_m * v_m)), 9.8, 1.0));
}
return v_s * tmp;
}
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, v_m, H) t_0 = atan(Float64(v_m / sqrt(Float64(Float64(v_m * v_m) - Float64(Float64(2.0 * 9.8) * H))))) tmp = 0.0 if (t_0 <= 0.0) tmp = atan(1.0); elseif (t_0 <= 0.6) tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v_m)); else tmp = atan(fma(Float64(H / Float64(v_m * v_m)), 9.8, 1.0)); end return Float64(v_s * tmp) end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := Block[{t$95$0 = N[ArcTan[N[(v$95$m / N[Sqrt[N[(N[(v$95$m * v$95$m), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(v$95$s * If[LessEqual[t$95$0, 0.0], N[ArcTan[1.0], $MachinePrecision], If[LessEqual[t$95$0, 0.6], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v$95$m), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(N[(H / N[(v$95$m * v$95$m), $MachinePrecision]), $MachinePrecision] * 9.8 + 1.0), $MachinePrecision]], $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\
v\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\tan^{-1} 1\\
\mathbf{elif}\;t\_0 \leq 0.6:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(\frac{H}{v\_m \cdot v\_m}, 9.8, 1\right)\right)\\
\end{array}
\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.0Initial program 12.0%
Taylor expanded in v around inf
Applied rewrites91.0%
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.599999999999999978Initial program 99.5%
Taylor expanded in v around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
metadata-evalN/A
+-commutativeN/A
lower-atan.f64N/A
*-commutativeN/A
Applied rewrites99.4%
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
lower-sqrt.f64N/A
sqrt-divN/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6499.4
Applied rewrites99.4%
Taylor expanded in v around 0
lower-/.f6498.7
Applied rewrites98.7%
if 0.599999999999999978 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) Initial program 99.9%
Taylor expanded in v around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6498.8
Applied rewrites98.8%
v\_m = (fabs.f64 v)
v\_s = (copysign.f64 #s(literal 1 binary64) v)
(FPCore (v_s v_m H)
:precision binary64
(let* ((t_0 (atan (/ v_m (sqrt (- (* v_m v_m) (* (* 2.0 9.8) H)))))))
(*
v_s
(if (<= t_0 0.0)
(atan 1.0)
(if (<= t_0 0.6)
(atan (* (sqrt (/ -0.05102040816326531 H)) v_m))
(atan 1.0))))))v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
double t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
double tmp;
if (t_0 <= 0.0) {
tmp = atan(1.0);
} else if (t_0 <= 0.6) {
tmp = atan((sqrt((-0.05102040816326531 / H)) * v_m));
} else {
tmp = atan(1.0);
}
return v_s * tmp;
}
v\_m = private
v\_s = private
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_s, v_m, h)
use fmin_fmax_functions
real(8), intent (in) :: v_s
real(8), intent (in) :: v_m
real(8), intent (in) :: h
real(8) :: t_0
real(8) :: tmp
t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0d0 * 9.8d0) * h)))))
if (t_0 <= 0.0d0) then
tmp = atan(1.0d0)
else if (t_0 <= 0.6d0) then
tmp = atan((sqrt(((-0.05102040816326531d0) / h)) * v_m))
else
tmp = atan(1.0d0)
end if
code = v_s * tmp
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double v_m, double H) {
double t_0 = Math.atan((v_m / Math.sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
double tmp;
if (t_0 <= 0.0) {
tmp = Math.atan(1.0);
} else if (t_0 <= 0.6) {
tmp = Math.atan((Math.sqrt((-0.05102040816326531 / H)) * v_m));
} else {
tmp = Math.atan(1.0);
}
return v_s * tmp;
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, v_m, H): t_0 = math.atan((v_m / math.sqrt(((v_m * v_m) - ((2.0 * 9.8) * H))))) tmp = 0 if t_0 <= 0.0: tmp = math.atan(1.0) elif t_0 <= 0.6: tmp = math.atan((math.sqrt((-0.05102040816326531 / H)) * v_m)) else: tmp = math.atan(1.0) return v_s * tmp
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, v_m, H) t_0 = atan(Float64(v_m / sqrt(Float64(Float64(v_m * v_m) - Float64(Float64(2.0 * 9.8) * H))))) tmp = 0.0 if (t_0 <= 0.0) tmp = atan(1.0); elseif (t_0 <= 0.6) tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v_m)); else tmp = atan(1.0); end return Float64(v_s * tmp) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp_2 = code(v_s, v_m, H) t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H))))); tmp = 0.0; if (t_0 <= 0.0) tmp = atan(1.0); elseif (t_0 <= 0.6) tmp = atan((sqrt((-0.05102040816326531 / H)) * v_m)); else tmp = atan(1.0); end tmp_2 = v_s * tmp; end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := Block[{t$95$0 = N[ArcTan[N[(v$95$m / N[Sqrt[N[(N[(v$95$m * v$95$m), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(v$95$s * If[LessEqual[t$95$0, 0.0], N[ArcTan[1.0], $MachinePrecision], If[LessEqual[t$95$0, 0.6], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v$95$m), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\
v\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\tan^{-1} 1\\
\mathbf{elif}\;t\_0 \leq 0.6:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\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.599999999999999978 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) Initial program 53.1%
Taylor expanded in v around inf
Applied rewrites94.1%
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.599999999999999978Initial program 99.5%
Taylor expanded in v around 0
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
metadata-evalN/A
+-commutativeN/A
lower-atan.f64N/A
*-commutativeN/A
Applied rewrites99.4%
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
lower-sqrt.f64N/A
sqrt-divN/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6499.4
Applied rewrites99.4%
Taylor expanded in v around 0
lower-/.f6498.7
Applied rewrites98.7%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s v_m H) :precision binary64 (* v_s (atan 1.0)))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
return v_s * atan(1.0);
}
v\_m = private
v\_s = private
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_s, v_m, h)
use fmin_fmax_functions
real(8), intent (in) :: v_s
real(8), intent (in) :: v_m
real(8), intent (in) :: h
code = v_s * atan(1.0d0)
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double v_m, double H) {
return v_s * Math.atan(1.0);
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, v_m, H): return v_s * math.atan(1.0)
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, v_m, H) return Float64(v_s * atan(1.0)) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, v_m, H) tmp = v_s * atan(1.0); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := N[(v$95$s * N[ArcTan[1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \tan^{-1} 1
\end{array}
Initial program 66.3%
Taylor expanded in v around inf
Applied rewrites68.7%
v\_m = (fabs.f64 v) v\_s = (copysign.f64 #s(literal 1 binary64) v) (FPCore (v_s v_m H) :precision binary64 (* v_s (atan -1.0)))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
return v_s * atan(-1.0);
}
v\_m = private
v\_s = private
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_s, v_m, h)
use fmin_fmax_functions
real(8), intent (in) :: v_s
real(8), intent (in) :: v_m
real(8), intent (in) :: h
code = v_s * atan((-1.0d0))
end function
v\_m = Math.abs(v);
v\_s = Math.copySign(1.0, v);
public static double code(double v_s, double v_m, double H) {
return v_s * Math.atan(-1.0);
}
v\_m = math.fabs(v) v\_s = math.copysign(1.0, v) def code(v_s, v_m, H): return v_s * math.atan(-1.0)
v\_m = abs(v) v\_s = copysign(1.0, v) function code(v_s, v_m, H) return Float64(v_s * atan(-1.0)) end
v\_m = abs(v); v\_s = sign(v) * abs(1.0); function tmp = code(v_s, v_m, H) tmp = v_s * atan(-1.0); end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := N[(v$95$s * N[ArcTan[-1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)
\\
v\_s \cdot \tan^{-1} -1
\end{array}
Initial program 66.3%
Taylor expanded in v around -inf
Applied rewrites1.8%
herbie shell --seed 2025121
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))