
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (sin (* (* 0.005555555555555556 angle) PI)) b))) (+ (pow a 2.0) (/ (pow t_0 1.0) (pow t_0 -1.0)))))
double code(double a, double b, double angle) {
double t_0 = sin(((0.005555555555555556 * angle) * ((double) M_PI))) * b;
return pow(a, 2.0) + (pow(t_0, 1.0) / pow(t_0, -1.0));
}
public static double code(double a, double b, double angle) {
double t_0 = Math.sin(((0.005555555555555556 * angle) * Math.PI)) * b;
return Math.pow(a, 2.0) + (Math.pow(t_0, 1.0) / Math.pow(t_0, -1.0));
}
def code(a, b, angle): t_0 = math.sin(((0.005555555555555556 * angle) * math.pi)) * b return math.pow(a, 2.0) + (math.pow(t_0, 1.0) / math.pow(t_0, -1.0))
function code(a, b, angle) t_0 = Float64(sin(Float64(Float64(0.005555555555555556 * angle) * pi)) * b) return Float64((a ^ 2.0) + Float64((t_0 ^ 1.0) / (t_0 ^ -1.0))) end
function tmp = code(a, b, angle) t_0 = sin(((0.005555555555555556 * angle) * pi)) * b; tmp = (a ^ 2.0) + ((t_0 ^ 1.0) / (t_0 ^ -1.0)); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[Sin[N[(N[(0.005555555555555556 * angle), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision]}, N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[Power[t$95$0, 1.0], $MachinePrecision] / N[Power[t$95$0, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \pi\right) \cdot b\\
{a}^{2} + \frac{{t\_0}^{1}}{{t\_0}^{-1}}
\end{array}
Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
Applied rewrites80.3%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* (sin (* (* 0.005555555555555556 angle) PI)) b) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((sin(((0.005555555555555556 * angle) * ((double) M_PI))) * b), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((Math.sin(((0.005555555555555556 * angle) * Math.PI)) * b), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((math.sin(((0.005555555555555556 * angle) * math.pi)) * b), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(sin(Float64(Float64(0.005555555555555556 * angle) * pi)) * b) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((sin(((0.005555555555555556 * angle) * pi)) * b) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(N[Sin[N[(N[(0.005555555555555556 * angle), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
{a}^{2} + {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \pi\right) \cdot b\right)}^{2}
Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-*.f6480.3%
Applied rewrites80.3%
(FPCore (a b angle)
:precision binary64
(if (<= (fabs angle) 3.15e-8)
(+
(pow (* 0.005555555555555556 (* (fabs angle) (* b PI))) 2.0)
(* a a))
(+
(*
(-
0.5
(*
0.5
(cos (* 2.0 (* (* 0.005555555555555556 (fabs angle)) PI)))))
(* b b))
(* a a))))double code(double a, double b, double angle) {
double tmp;
if (fabs(angle) <= 3.15e-8) {
tmp = pow((0.005555555555555556 * (fabs(angle) * (b * ((double) M_PI)))), 2.0) + (a * a);
} else {
tmp = ((0.5 - (0.5 * cos((2.0 * ((0.005555555555555556 * fabs(angle)) * ((double) M_PI)))))) * (b * b)) + (a * a);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (Math.abs(angle) <= 3.15e-8) {
tmp = Math.pow((0.005555555555555556 * (Math.abs(angle) * (b * Math.PI))), 2.0) + (a * a);
} else {
tmp = ((0.5 - (0.5 * Math.cos((2.0 * ((0.005555555555555556 * Math.abs(angle)) * Math.PI))))) * (b * b)) + (a * a);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if math.fabs(angle) <= 3.15e-8: tmp = math.pow((0.005555555555555556 * (math.fabs(angle) * (b * math.pi))), 2.0) + (a * a) else: tmp = ((0.5 - (0.5 * math.cos((2.0 * ((0.005555555555555556 * math.fabs(angle)) * math.pi))))) * (b * b)) + (a * a) return tmp
function code(a, b, angle) tmp = 0.0 if (abs(angle) <= 3.15e-8) tmp = Float64((Float64(0.005555555555555556 * Float64(abs(angle) * Float64(b * pi))) ^ 2.0) + Float64(a * a)); else tmp = Float64(Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * Float64(Float64(0.005555555555555556 * abs(angle)) * pi))))) * Float64(b * b)) + Float64(a * a)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (abs(angle) <= 3.15e-8) tmp = ((0.005555555555555556 * (abs(angle) * (b * pi))) ^ 2.0) + (a * a); else tmp = ((0.5 - (0.5 * cos((2.0 * ((0.005555555555555556 * abs(angle)) * pi))))) * (b * b)) + (a * a); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[N[Abs[angle], $MachinePrecision], 3.15e-8], N[(N[Power[N[(0.005555555555555556 * N[(N[Abs[angle], $MachinePrecision] * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * N[(N[(0.005555555555555556 * N[Abs[angle], $MachinePrecision]), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|angle\right| \leq 3.15 \cdot 10^{-8}:\\
\;\;\;\;{\left(0.005555555555555556 \cdot \left(\left|angle\right| \cdot \left(b \cdot \pi\right)\right)\right)}^{2} + a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\left(0.005555555555555556 \cdot \left|angle\right|\right) \cdot \pi\right)\right)\right) \cdot \left(b \cdot b\right) + a \cdot a\\
\end{array}
if angle < 3.1499999999999998e-8Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
Applied rewrites80.3%
Applied rewrites80.3%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6475.5%
Applied rewrites75.5%
if 3.1499999999999998e-8 < angle Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
Applied rewrites63.6%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* 0.017453292519943295 angle))) 2.0) (* a a)))
double code(double a, double b, double angle) {
return pow((b * sin((0.017453292519943295 * angle))), 2.0) + (a * a);
}
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(a, b, angle)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = ((b * sin((0.017453292519943295d0 * angle))) ** 2.0d0) + (a * a)
end function
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin((0.017453292519943295 * angle))), 2.0) + (a * a);
}
def code(a, b, angle): return math.pow((b * math.sin((0.017453292519943295 * angle))), 2.0) + (a * a)
function code(a, b, angle) return Float64((Float64(b * sin(Float64(0.017453292519943295 * angle))) ^ 2.0) + Float64(a * a)) end
function tmp = code(a, b, angle) tmp = ((b * sin((0.017453292519943295 * angle))) ^ 2.0) + (a * a); end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(0.017453292519943295 * angle), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]
{\left(b \cdot \sin \left(0.017453292519943295 \cdot angle\right)\right)}^{2} + a \cdot a
Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
Applied rewrites80.3%
Applied rewrites80.3%
Evaluated real constant80.3%
(FPCore (a b angle)
:precision binary64
(if (<= (fabs angle) 5.5e-10)
(+
(pow (* 0.005555555555555556 (* (fabs angle) (* b PI))) 2.0)
(* a a))
(+
(*
(*
(-
0.5
(* 0.5 (cos (* 0.011111111111111112 (* (fabs angle) PI)))))
b)
b)
(* (* 1.0 a) a))))double code(double a, double b, double angle) {
double tmp;
if (fabs(angle) <= 5.5e-10) {
tmp = pow((0.005555555555555556 * (fabs(angle) * (b * ((double) M_PI)))), 2.0) + (a * a);
} else {
tmp = (((0.5 - (0.5 * cos((0.011111111111111112 * (fabs(angle) * ((double) M_PI)))))) * b) * b) + ((1.0 * a) * a);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (Math.abs(angle) <= 5.5e-10) {
tmp = Math.pow((0.005555555555555556 * (Math.abs(angle) * (b * Math.PI))), 2.0) + (a * a);
} else {
tmp = (((0.5 - (0.5 * Math.cos((0.011111111111111112 * (Math.abs(angle) * Math.PI))))) * b) * b) + ((1.0 * a) * a);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if math.fabs(angle) <= 5.5e-10: tmp = math.pow((0.005555555555555556 * (math.fabs(angle) * (b * math.pi))), 2.0) + (a * a) else: tmp = (((0.5 - (0.5 * math.cos((0.011111111111111112 * (math.fabs(angle) * math.pi))))) * b) * b) + ((1.0 * a) * a) return tmp
function code(a, b, angle) tmp = 0.0 if (abs(angle) <= 5.5e-10) tmp = Float64((Float64(0.005555555555555556 * Float64(abs(angle) * Float64(b * pi))) ^ 2.0) + Float64(a * a)); else tmp = Float64(Float64(Float64(Float64(0.5 - Float64(0.5 * cos(Float64(0.011111111111111112 * Float64(abs(angle) * pi))))) * b) * b) + Float64(Float64(1.0 * a) * a)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (abs(angle) <= 5.5e-10) tmp = ((0.005555555555555556 * (abs(angle) * (b * pi))) ^ 2.0) + (a * a); else tmp = (((0.5 - (0.5 * cos((0.011111111111111112 * (abs(angle) * pi))))) * b) * b) + ((1.0 * a) * a); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[N[Abs[angle], $MachinePrecision], 5.5e-10], N[(N[Power[N[(0.005555555555555556 * N[(N[Abs[angle], $MachinePrecision] * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 - N[(0.5 * N[Cos[N[(0.011111111111111112 * N[(N[Abs[angle], $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision] + N[(N[(1.0 * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|angle\right| \leq 5.5 \cdot 10^{-10}:\\
\;\;\;\;{\left(0.005555555555555556 \cdot \left(\left|angle\right| \cdot \left(b \cdot \pi\right)\right)\right)}^{2} + a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(0.5 - 0.5 \cdot \cos \left(0.011111111111111112 \cdot \left(\left|angle\right| \cdot \pi\right)\right)\right) \cdot b\right) \cdot b + \left(1 \cdot a\right) \cdot a\\
\end{array}
if angle < 5.4999999999999996e-10Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
Applied rewrites80.3%
Applied rewrites80.3%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6475.5%
Applied rewrites75.5%
if 5.4999999999999996e-10 < angle Initial program 80.3%
Applied rewrites68.9%
Taylor expanded in angle around 0
Applied rewrites57.5%
Taylor expanded in angle around 0
Applied rewrites57.7%
Taylor expanded in angle around 0
Applied rewrites57.7%
Taylor expanded in angle around inf
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6468.9%
Applied rewrites68.9%
(FPCore (a b angle) :precision binary64 (if (<= (fabs b) 4.2e-97) (+ (* (* (- 0.5 0.5) (fabs b)) (fabs b)) (* (* 1.0 a) a)) (+ (pow (* 0.005555555555555556 (* angle (* (fabs b) PI))) 2.0) (* a a))))
double code(double a, double b, double angle) {
double tmp;
if (fabs(b) <= 4.2e-97) {
tmp = (((0.5 - 0.5) * fabs(b)) * fabs(b)) + ((1.0 * a) * a);
} else {
tmp = pow((0.005555555555555556 * (angle * (fabs(b) * ((double) M_PI)))), 2.0) + (a * a);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (Math.abs(b) <= 4.2e-97) {
tmp = (((0.5 - 0.5) * Math.abs(b)) * Math.abs(b)) + ((1.0 * a) * a);
} else {
tmp = Math.pow((0.005555555555555556 * (angle * (Math.abs(b) * Math.PI))), 2.0) + (a * a);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if math.fabs(b) <= 4.2e-97: tmp = (((0.5 - 0.5) * math.fabs(b)) * math.fabs(b)) + ((1.0 * a) * a) else: tmp = math.pow((0.005555555555555556 * (angle * (math.fabs(b) * math.pi))), 2.0) + (a * a) return tmp
function code(a, b, angle) tmp = 0.0 if (abs(b) <= 4.2e-97) tmp = Float64(Float64(Float64(Float64(0.5 - 0.5) * abs(b)) * abs(b)) + Float64(Float64(1.0 * a) * a)); else tmp = Float64((Float64(0.005555555555555556 * Float64(angle * Float64(abs(b) * pi))) ^ 2.0) + Float64(a * a)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (abs(b) <= 4.2e-97) tmp = (((0.5 - 0.5) * abs(b)) * abs(b)) + ((1.0 * a) * a); else tmp = ((0.005555555555555556 * (angle * (abs(b) * pi))) ^ 2.0) + (a * a); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[N[Abs[b], $MachinePrecision], 4.2e-97], N[(N[(N[(N[(0.5 - 0.5), $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.005555555555555556 * N[(angle * N[(N[Abs[b], $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|b\right| \leq 4.2 \cdot 10^{-97}:\\
\;\;\;\;\left(\left(0.5 - 0.5\right) \cdot \left|b\right|\right) \cdot \left|b\right| + \left(1 \cdot a\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(0.005555555555555556 \cdot \left(angle \cdot \left(\left|b\right| \cdot \pi\right)\right)\right)}^{2} + a \cdot a\\
\end{array}
if b < 4.2000000000000002e-97Initial program 80.3%
Applied rewrites68.9%
Taylor expanded in angle around 0
Applied rewrites57.5%
Taylor expanded in angle around 0
Applied rewrites57.7%
Taylor expanded in angle around 0
Applied rewrites57.7%
if 4.2000000000000002e-97 < b Initial program 80.3%
Taylor expanded in angle around 0
lower-pow.f6480.3%
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
pow-subN/A
lower-unsound-/.f64N/A
Applied rewrites80.3%
Applied rewrites80.3%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6475.5%
Applied rewrites75.5%
(FPCore (a b angle) :precision binary64 (+ (* (* (- 0.5 0.5) b) b) (* (* 1.0 a) a)))
double code(double a, double b, double angle) {
return (((0.5 - 0.5) * b) * b) + ((1.0 * a) * a);
}
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(a, b, angle)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = (((0.5d0 - 0.5d0) * b) * b) + ((1.0d0 * a) * a)
end function
public static double code(double a, double b, double angle) {
return (((0.5 - 0.5) * b) * b) + ((1.0 * a) * a);
}
def code(a, b, angle): return (((0.5 - 0.5) * b) * b) + ((1.0 * a) * a)
function code(a, b, angle) return Float64(Float64(Float64(Float64(0.5 - 0.5) * b) * b) + Float64(Float64(1.0 * a) * a)) end
function tmp = code(a, b, angle) tmp = (((0.5 - 0.5) * b) * b) + ((1.0 * a) * a); end
code[a_, b_, angle_] := N[(N[(N[(N[(0.5 - 0.5), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision] + N[(N[(1.0 * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]
\left(\left(0.5 - 0.5\right) \cdot b\right) \cdot b + \left(1 \cdot a\right) \cdot a
Initial program 80.3%
Applied rewrites68.9%
Taylor expanded in angle around 0
Applied rewrites57.5%
Taylor expanded in angle around 0
Applied rewrites57.7%
Taylor expanded in angle around 0
Applied rewrites57.7%
herbie shell --seed 2025258
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))