
(FPCore (eh ew t) :precision binary64 (let* ((t_1 (atan (/ (* (- eh) (tan t)) ew)))) (fabs (- (* (* ew (cos t)) (cos t_1)) (* (* eh (sin t)) (sin t_1))))))
double code(double eh, double ew, double t) {
double t_1 = atan(((-eh * tan(t)) / ew));
return fabs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))));
}
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(eh, ew, t)
use fmin_fmax_functions
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: t_1
t_1 = atan(((-eh * tan(t)) / ew))
code = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))))
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.atan(((-eh * Math.tan(t)) / ew));
return Math.abs((((ew * Math.cos(t)) * Math.cos(t_1)) - ((eh * Math.sin(t)) * Math.sin(t_1))));
}
def code(eh, ew, t): t_1 = math.atan(((-eh * math.tan(t)) / ew)) return math.fabs((((ew * math.cos(t)) * math.cos(t_1)) - ((eh * math.sin(t)) * math.sin(t_1))))
function code(eh, ew, t) t_1 = atan(Float64(Float64(Float64(-eh) * tan(t)) / ew)) return abs(Float64(Float64(Float64(ew * cos(t)) * cos(t_1)) - Float64(Float64(eh * sin(t)) * sin(t_1)))) end
function tmp = code(eh, ew, t) t_1 = atan(((-eh * tan(t)) / ew)); tmp = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1)))); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcTan[N[(N[((-eh) * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\\
\left|\left(ew \cdot \cos t\right) \cdot \cos t\_1 - \left(eh \cdot \sin t\right) \cdot \sin t\_1\right|
\end{array}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (eh ew t) :precision binary64 (let* ((t_1 (atan (/ (* (- eh) (tan t)) ew)))) (fabs (- (* (* ew (cos t)) (cos t_1)) (* (* eh (sin t)) (sin t_1))))))
double code(double eh, double ew, double t) {
double t_1 = atan(((-eh * tan(t)) / ew));
return fabs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))));
}
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(eh, ew, t)
use fmin_fmax_functions
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
real(8) :: t_1
t_1 = atan(((-eh * tan(t)) / ew))
code = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1))))
end function
public static double code(double eh, double ew, double t) {
double t_1 = Math.atan(((-eh * Math.tan(t)) / ew));
return Math.abs((((ew * Math.cos(t)) * Math.cos(t_1)) - ((eh * Math.sin(t)) * Math.sin(t_1))));
}
def code(eh, ew, t): t_1 = math.atan(((-eh * math.tan(t)) / ew)) return math.fabs((((ew * math.cos(t)) * math.cos(t_1)) - ((eh * math.sin(t)) * math.sin(t_1))))
function code(eh, ew, t) t_1 = atan(Float64(Float64(Float64(-eh) * tan(t)) / ew)) return abs(Float64(Float64(Float64(ew * cos(t)) * cos(t_1)) - Float64(Float64(eh * sin(t)) * sin(t_1)))) end
function tmp = code(eh, ew, t) t_1 = atan(((-eh * tan(t)) / ew)); tmp = abs((((ew * cos(t)) * cos(t_1)) - ((eh * sin(t)) * sin(t_1)))); end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcTan[N[(N[((-eh) * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\\
\left|\left(ew \cdot \cos t\right) \cdot \cos t\_1 - \left(eh \cdot \sin t\right) \cdot \sin t\_1\right|
\end{array}
\end{array}
(FPCore (eh ew t) :precision binary64 (let* ((t_1 (asinh (* (/ (tan t) ew) eh)))) (fabs (fma (/ ew (cosh t_1)) (cos t) (* (tanh t_1) (* (sin t) eh))))))
double code(double eh, double ew, double t) {
double t_1 = asinh(((tan(t) / ew) * eh));
return fabs(fma((ew / cosh(t_1)), cos(t), (tanh(t_1) * (sin(t) * eh))));
}
function code(eh, ew, t) t_1 = asinh(Float64(Float64(tan(t) / ew) * eh)) return abs(fma(Float64(ew / cosh(t_1)), cos(t), Float64(tanh(t_1) * Float64(sin(t) * eh)))) end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcSinh[N[(N[(N[Tan[t], $MachinePrecision] / ew), $MachinePrecision] * eh), $MachinePrecision]], $MachinePrecision]}, N[Abs[N[(N[(ew / N[Cosh[t$95$1], $MachinePrecision]), $MachinePrecision] * N[Cos[t], $MachinePrecision] + N[(N[Tanh[t$95$1], $MachinePrecision] * N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \sinh^{-1} \left(\frac{\tan t}{ew} \cdot eh\right)\\
\left|\mathsf{fma}\left(\frac{ew}{\cosh t\_1}, \cos t, \tanh t\_1 \cdot \left(\sin t \cdot eh\right)\right)\right|
\end{array}
\end{array}
Initial program 99.8%
Applied rewrites99.8%
(FPCore (eh ew t) :precision binary64 (fabs (fma ew (cos t) (* (tanh (asinh (* (/ (tan t) ew) eh))) (* (sin t) eh)))))
double code(double eh, double ew, double t) {
return fabs(fma(ew, cos(t), (tanh(asinh(((tan(t) / ew) * eh))) * (sin(t) * eh))));
}
function code(eh, ew, t) return abs(fma(ew, cos(t), Float64(tanh(asinh(Float64(Float64(tan(t) / ew) * eh))) * Float64(sin(t) * eh)))) end
code[eh_, ew_, t_] := N[Abs[N[(ew * N[Cos[t], $MachinePrecision] + N[(N[Tanh[N[ArcSinh[N[(N[(N[Tan[t], $MachinePrecision] / ew), $MachinePrecision] * eh), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\mathsf{fma}\left(ew, \cos t, \tanh \sinh^{-1} \left(\frac{\tan t}{ew} \cdot eh\right) \cdot \left(\sin t \cdot eh\right)\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
Applied rewrites98.5%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (asinh (* (/ t ew) eh))))
(if (<= ew 4.2e+93)
(fabs (fma (/ ew (cosh t_1)) (cos t) (* (tanh t_1) (* (sin t) eh))))
(fabs (* ew (cos t))))))
double code(double eh, double ew, double t) {
double t_1 = asinh(((t / ew) * eh));
double tmp;
if (ew <= 4.2e+93) {
tmp = fabs(fma((ew / cosh(t_1)), cos(t), (tanh(t_1) * (sin(t) * eh))));
} else {
tmp = fabs((ew * cos(t)));
}
return tmp;
}
function code(eh, ew, t) t_1 = asinh(Float64(Float64(t / ew) * eh)) tmp = 0.0 if (ew <= 4.2e+93) tmp = abs(fma(Float64(ew / cosh(t_1)), cos(t), Float64(tanh(t_1) * Float64(sin(t) * eh)))); else tmp = abs(Float64(ew * cos(t))); end return tmp end
code[eh_, ew_, t_] := Block[{t$95$1 = N[ArcSinh[N[(N[(t / ew), $MachinePrecision] * eh), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[ew, 4.2e+93], N[Abs[N[(N[(ew / N[Cosh[t$95$1], $MachinePrecision]), $MachinePrecision] * N[Cos[t], $MachinePrecision] + N[(N[Tanh[t$95$1], $MachinePrecision] * N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \sinh^{-1} \left(\frac{t}{ew} \cdot eh\right)\\
\mathbf{if}\;ew \leq 4.2 \cdot 10^{+93}:\\
\;\;\;\;\left|\mathsf{fma}\left(\frac{ew}{\cosh t\_1}, \cos t, \tanh t\_1 \cdot \left(\sin t \cdot eh\right)\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|ew \cdot \cos t\right|\\
\end{array}
\end{array}
if ew < 4.1999999999999996e93Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in t around 0
Applied rewrites90.1%
Taylor expanded in t around 0
Applied rewrites90.2%
if 4.1999999999999996e93 < ew Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
(FPCore (eh ew t)
:precision binary64
(let* ((t_1 (/ (* eh t) ew)))
(if (<= ew 3.8e+76)
(fabs (fma (/ ew (cosh t_1)) (cos t) (* (tanh t_1) (* (sin t) eh))))
(fabs (* ew (cos t))))))
double code(double eh, double ew, double t) {
double t_1 = (eh * t) / ew;
double tmp;
if (ew <= 3.8e+76) {
tmp = fabs(fma((ew / cosh(t_1)), cos(t), (tanh(t_1) * (sin(t) * eh))));
} else {
tmp = fabs((ew * cos(t)));
}
return tmp;
}
function code(eh, ew, t) t_1 = Float64(Float64(eh * t) / ew) tmp = 0.0 if (ew <= 3.8e+76) tmp = abs(fma(Float64(ew / cosh(t_1)), cos(t), Float64(tanh(t_1) * Float64(sin(t) * eh)))); else tmp = abs(Float64(ew * cos(t))); end return tmp end
code[eh_, ew_, t_] := Block[{t$95$1 = N[(N[(eh * t), $MachinePrecision] / ew), $MachinePrecision]}, If[LessEqual[ew, 3.8e+76], N[Abs[N[(N[(ew / N[Cosh[t$95$1], $MachinePrecision]), $MachinePrecision] * N[Cos[t], $MachinePrecision] + N[(N[Tanh[t$95$1], $MachinePrecision] * N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{eh \cdot t}{ew}\\
\mathbf{if}\;ew \leq 3.8 \cdot 10^{+76}:\\
\;\;\;\;\left|\mathsf{fma}\left(\frac{ew}{\cosh t\_1}, \cos t, \tanh t\_1 \cdot \left(\sin t \cdot eh\right)\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|ew \cdot \cos t\right|\\
\end{array}
\end{array}
if ew < 3.80000000000000024e76Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in t around 0
lower-/.f64N/A
lower-*.f6489.6
Applied rewrites89.6%
Taylor expanded in t around 0
lower-/.f64N/A
lower-*.f6489.8
Applied rewrites89.8%
if 3.80000000000000024e76 < ew Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
(FPCore (eh ew t) :precision binary64 (if (<= eh 5.4e+133) (fabs (* ew (cos t))) (fabs (* (* (sin t) eh) (tanh (asinh (* eh (/ (tan (+ PI t)) ew))))))))
double code(double eh, double ew, double t) {
double tmp;
if (eh <= 5.4e+133) {
tmp = fabs((ew * cos(t)));
} else {
tmp = fabs(((sin(t) * eh) * tanh(asinh((eh * (tan((((double) M_PI) + t)) / ew))))));
}
return tmp;
}
def code(eh, ew, t): tmp = 0 if eh <= 5.4e+133: tmp = math.fabs((ew * math.cos(t))) else: tmp = math.fabs(((math.sin(t) * eh) * math.tanh(math.asinh((eh * (math.tan((math.pi + t)) / ew)))))) return tmp
function code(eh, ew, t) tmp = 0.0 if (eh <= 5.4e+133) tmp = abs(Float64(ew * cos(t))); else tmp = abs(Float64(Float64(sin(t) * eh) * tanh(asinh(Float64(eh * Float64(tan(Float64(pi + t)) / ew)))))); end return tmp end
function tmp_2 = code(eh, ew, t) tmp = 0.0; if (eh <= 5.4e+133) tmp = abs((ew * cos(t))); else tmp = abs(((sin(t) * eh) * tanh(asinh((eh * (tan((pi + t)) / ew)))))); end tmp_2 = tmp; end
code[eh_, ew_, t_] := If[LessEqual[eh, 5.4e+133], N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision] * N[Tanh[N[ArcSinh[N[(eh * N[(N[Tan[N[(Pi + t), $MachinePrecision]], $MachinePrecision] / ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;eh \leq 5.4 \cdot 10^{+133}:\\
\;\;\;\;\left|ew \cdot \cos t\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(eh \cdot \frac{\tan \left(\pi + t\right)}{ew}\right)\right|\\
\end{array}
\end{array}
if eh < 5.4000000000000004e133Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
if 5.4000000000000004e133 < eh Initial program 99.8%
Taylor expanded in eh around inf
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
lower-atan.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
Applied rewrites41.5%
Applied rewrites41.5%
lift-tan.f64N/A
tan-+PI-revN/A
lower-tan.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-PI.f6441.7
Applied rewrites41.7%
(FPCore (eh ew t) :precision binary64 (if (<= eh 5.4e+133) (fabs (* ew (cos t))) (fabs (* (* (sin t) eh) (tanh (asinh (* eh (/ t ew))))))))
double code(double eh, double ew, double t) {
double tmp;
if (eh <= 5.4e+133) {
tmp = fabs((ew * cos(t)));
} else {
tmp = fabs(((sin(t) * eh) * tanh(asinh((eh * (t / ew))))));
}
return tmp;
}
def code(eh, ew, t): tmp = 0 if eh <= 5.4e+133: tmp = math.fabs((ew * math.cos(t))) else: tmp = math.fabs(((math.sin(t) * eh) * math.tanh(math.asinh((eh * (t / ew)))))) return tmp
function code(eh, ew, t) tmp = 0.0 if (eh <= 5.4e+133) tmp = abs(Float64(ew * cos(t))); else tmp = abs(Float64(Float64(sin(t) * eh) * tanh(asinh(Float64(eh * Float64(t / ew)))))); end return tmp end
function tmp_2 = code(eh, ew, t) tmp = 0.0; if (eh <= 5.4e+133) tmp = abs((ew * cos(t))); else tmp = abs(((sin(t) * eh) * tanh(asinh((eh * (t / ew)))))); end tmp_2 = tmp; end
code[eh_, ew_, t_] := If[LessEqual[eh, 5.4e+133], N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[Sin[t], $MachinePrecision] * eh), $MachinePrecision] * N[Tanh[N[ArcSinh[N[(eh * N[(t / ew), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;eh \leq 5.4 \cdot 10^{+133}:\\
\;\;\;\;\left|ew \cdot \cos t\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\left(\sin t \cdot eh\right) \cdot \tanh \sinh^{-1} \left(eh \cdot \frac{t}{ew}\right)\right|\\
\end{array}
\end{array}
if eh < 5.4000000000000004e133Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
if 5.4000000000000004e133 < eh Initial program 99.8%
Taylor expanded in eh around inf
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
lower-atan.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
Applied rewrites41.5%
Applied rewrites41.5%
Taylor expanded in t around 0
lower-/.f6441.7
Applied rewrites41.7%
(FPCore (eh ew t) :precision binary64 (fabs (* ew (cos t))))
double code(double eh, double ew, double t) {
return fabs((ew * cos(t)));
}
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(eh, ew, t)
use fmin_fmax_functions
real(8), intent (in) :: eh
real(8), intent (in) :: ew
real(8), intent (in) :: t
code = abs((ew * cos(t)))
end function
public static double code(double eh, double ew, double t) {
return Math.abs((ew * Math.cos(t)));
}
def code(eh, ew, t): return math.fabs((ew * math.cos(t)))
function code(eh, ew, t) return abs(Float64(ew * cos(t))) end
function tmp = code(eh, ew, t) tmp = abs((ew * cos(t))); end
code[eh_, ew_, t_] := N[Abs[N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|ew \cdot \cos t\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
(FPCore (eh ew t) :precision binary64 (if (<= t 380000000.0) (fabs (* (fma (* t t) -0.5 1.0) ew)) (sqrt (pow ew 2.0))))
double code(double eh, double ew, double t) {
double tmp;
if (t <= 380000000.0) {
tmp = fabs((fma((t * t), -0.5, 1.0) * ew));
} else {
tmp = sqrt(pow(ew, 2.0));
}
return tmp;
}
function code(eh, ew, t) tmp = 0.0 if (t <= 380000000.0) tmp = abs(Float64(fma(Float64(t * t), -0.5, 1.0) * ew)); else tmp = sqrt((ew ^ 2.0)); end return tmp end
code[eh_, ew_, t_] := If[LessEqual[t, 380000000.0], N[Abs[N[(N[(N[(t * t), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[Power[ew, 2.0], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 380000000:\\
\;\;\;\;\left|\mathsf{fma}\left(t \cdot t, -0.5, 1\right) \cdot ew\right|\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{ew}^{2}}\\
\end{array}
\end{array}
if t < 3.8e8Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
Taylor expanded in t around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6438.1
Applied rewrites38.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6438.1
lift-pow.f64N/A
unpow2N/A
lower-*.f6438.1
Applied rewrites38.1%
if 3.8e8 < t Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
lower-sqrt.f64N/A
pow2N/A
Applied rewrites34.2%
Taylor expanded in t around 0
lower-pow.f6424.5
Applied rewrites24.5%
(FPCore (eh ew t) :precision binary64 (fabs (* (fma (* t t) -0.5 1.0) ew)))
double code(double eh, double ew, double t) {
return fabs((fma((t * t), -0.5, 1.0) * ew));
}
function code(eh, ew, t) return abs(Float64(fma(Float64(t * t), -0.5, 1.0) * ew)) end
code[eh_, ew_, t_] := N[Abs[N[(N[(N[(t * t), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * ew), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\mathsf{fma}\left(t \cdot t, -0.5, 1\right) \cdot ew\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in eh around 0
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
Taylor expanded in t around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6438.1
Applied rewrites38.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6438.1
lift-pow.f64N/A
unpow2N/A
lower-*.f6438.1
Applied rewrites38.1%
herbie shell --seed 2025156
(FPCore (eh ew t)
:name "Example 2 from Robby"
:precision binary64
(fabs (- (* (* ew (cos t)) (cos (atan (/ (* (- eh) (tan t)) ew)))) (* (* eh (sin t)) (sin (atan (/ (* (- eh) (tan t)) ew)))))))