
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
t_0)))
double code(double A, double B, double C, double F) {
double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
return -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_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(a, b, c, f)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: t_0
t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) - sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F): t_0 = math.pow(B, 2.0) - ((4.0 * A) * C) return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F) t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0) end
function tmp = code(A, B, C, F) t_0 = (B ^ 2.0) - ((4.0 * A) * C); tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0; end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
t_0)))
double code(double A, double B, double C, double F) {
double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
return -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_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(a, b, c, f)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: t_0
t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) - sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F): t_0 = math.pow(B, 2.0) - ((4.0 * A) * C) return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F) t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0) end
function tmp = code(A, B, C, F) t_0 = (B ^ 2.0) - ((4.0 * A) * C); tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0; end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0}
\end{array}
\end{array}
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(if (<= B_m 3.6e-13)
(/
(sqrt
(*
(* 2.0 (* (- (pow B_m 2.0) (* (* 4.0 A) C)) F))
(+ (+ A (* -0.5 (/ (* B_m B_m) C))) A)))
(- (* -1.0 (pow B_m 2.0)) (* (* (* -1.0 4.0) A) C)))
(* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 3.6e-13) {
tmp = sqrt(((2.0 * ((pow(B_m, 2.0) - ((4.0 * A) * C)) * F)) * ((A + (-0.5 * ((B_m * B_m) / C))) + A))) / ((-1.0 * pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 3.6e-13) {
tmp = Math.sqrt(((2.0 * ((Math.pow(B_m, 2.0) - ((4.0 * A) * C)) * F)) * ((A + (-0.5 * ((B_m * B_m) / C))) + A))) / ((-1.0 * Math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (Math.pow(2.0, 0.5) / B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if B_m <= 3.6e-13: tmp = math.sqrt(((2.0 * ((math.pow(B_m, 2.0) - ((4.0 * A) * C)) * F)) * ((A + (-0.5 * ((B_m * B_m) / C))) + A))) / ((-1.0 * math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C)) else: tmp = (-1.0 * (math.pow(2.0, 0.5) / B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (B_m <= 3.6e-13) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64((B_m ^ 2.0) - Float64(Float64(4.0 * A) * C)) * F)) * Float64(Float64(A + Float64(-0.5 * Float64(Float64(B_m * B_m) / C))) + A))) / Float64(Float64(-1.0 * (B_m ^ 2.0)) - Float64(Float64(Float64(-1.0 * 4.0) * A) * C))); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (B_m <= 3.6e-13)
tmp = sqrt(((2.0 * (((B_m ^ 2.0) - ((4.0 * A) * C)) * F)) * ((A + (-0.5 * ((B_m * B_m) / C))) + A))) / ((-1.0 * (B_m ^ 2.0)) - (((-1.0 * 4.0) * A) * C));
else
tmp = (-1.0 * ((2.0 ^ 0.5) / B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[B$95$m, 3.6e-13], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B$95$m, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + N[(-0.5 * N[(N[(B$95$m * B$95$m), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(-1.0 * N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(-1.0 * 4.0), $MachinePrecision] * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B\_m \leq 3.6 \cdot 10^{-13}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left({B\_m}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + -0.5 \cdot \frac{B\_m \cdot B\_m}{C}\right) + A\right)}}{-1 \cdot {B\_m}^{2} - \left(\left(-1 \cdot 4\right) \cdot A\right) \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if B < 3.5999999999999998e-13Initial program 17.4%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6419.5
Applied rewrites19.5%
if 3.5999999999999998e-13 < B Initial program 9.5%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
Applied rewrites40.4%
Final simplification24.3%
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(if (<= B_m 3.6e-13)
(/
(sqrt
(*
(* 2.0 (* (- (pow B_m 2.0) (* (* 4.0 A) C)) F))
(/ (fma -0.5 (pow B_m 2.0) (* C (- A (* -1.0 A)))) C)))
(- (* -1.0 (pow B_m 2.0)) (* (* (* -1.0 4.0) A) C)))
(* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 3.6e-13) {
tmp = sqrt(((2.0 * ((pow(B_m, 2.0) - ((4.0 * A) * C)) * F)) * (fma(-0.5, pow(B_m, 2.0), (C * (A - (-1.0 * A)))) / C))) / ((-1.0 * pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (B_m <= 3.6e-13) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64((B_m ^ 2.0) - Float64(Float64(4.0 * A) * C)) * F)) * Float64(fma(-0.5, (B_m ^ 2.0), Float64(C * Float64(A - Float64(-1.0 * A)))) / C))) / Float64(Float64(-1.0 * (B_m ^ 2.0)) - Float64(Float64(Float64(-1.0 * 4.0) * A) * C))); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[B$95$m, 3.6e-13], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B$95$m, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(-0.5 * N[Power[B$95$m, 2.0], $MachinePrecision] + N[(C * N[(A - N[(-1.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(-1.0 * N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(-1.0 * 4.0), $MachinePrecision] * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B\_m \leq 3.6 \cdot 10^{-13}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left({B\_m}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \frac{\mathsf{fma}\left(-0.5, {B\_m}^{2}, C \cdot \left(A - -1 \cdot A\right)\right)}{C}}}{-1 \cdot {B\_m}^{2} - \left(\left(-1 \cdot 4\right) \cdot A\right) \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if B < 3.5999999999999998e-13Initial program 17.4%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6419.5
Applied rewrites19.5%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f6419.5
Applied rewrites19.5%
if 3.5999999999999998e-13 < B Initial program 9.5%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
Applied rewrites40.4%
Final simplification24.3%
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(if (<= B_m 3.4e-13)
(/
(sqrt (* -8.0 (* A (* C (* F (- A (* -1.0 A)))))))
(- (* -1.0 (pow B_m 2.0)) (* (* (* -1.0 4.0) A) C)))
(* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 3.4e-13) {
tmp = sqrt((-8.0 * (A * (C * (F * (A - (-1.0 * A))))))) / ((-1.0 * pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 3.4e-13) {
tmp = Math.sqrt((-8.0 * (A * (C * (F * (A - (-1.0 * A))))))) / ((-1.0 * Math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (Math.pow(2.0, 0.5) / B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if B_m <= 3.4e-13: tmp = math.sqrt((-8.0 * (A * (C * (F * (A - (-1.0 * A))))))) / ((-1.0 * math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C)) else: tmp = (-1.0 * (math.pow(2.0, 0.5) / B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (B_m <= 3.4e-13) tmp = Float64(sqrt(Float64(-8.0 * Float64(A * Float64(C * Float64(F * Float64(A - Float64(-1.0 * A))))))) / Float64(Float64(-1.0 * (B_m ^ 2.0)) - Float64(Float64(Float64(-1.0 * 4.0) * A) * C))); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (B_m <= 3.4e-13)
tmp = sqrt((-8.0 * (A * (C * (F * (A - (-1.0 * A))))))) / ((-1.0 * (B_m ^ 2.0)) - (((-1.0 * 4.0) * A) * C));
else
tmp = (-1.0 * ((2.0 ^ 0.5) / B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[B$95$m, 3.4e-13], N[(N[Sqrt[N[(-8.0 * N[(A * N[(C * N[(F * N[(A - N[(-1.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(-1.0 * N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(-1.0 * 4.0), $MachinePrecision] * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B\_m \leq 3.4 \cdot 10^{-13}:\\
\;\;\;\;\frac{\sqrt{-8 \cdot \left(A \cdot \left(C \cdot \left(F \cdot \left(A - -1 \cdot A\right)\right)\right)\right)}}{-1 \cdot {B\_m}^{2} - \left(\left(-1 \cdot 4\right) \cdot A\right) \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if B < 3.40000000000000015e-13Initial program 17.4%
Taylor expanded in C around inf
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6417.8
Applied rewrites17.8%
if 3.40000000000000015e-13 < B Initial program 9.5%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
Applied rewrites40.4%
Final simplification23.0%
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(if (<= B_m 1.4e-247)
(* (pow (* -0.5 (/ F C)) 0.5) (pow 2.0 0.5))
(if (<= B_m 3e-15)
(/
(sqrt (* (- -8.0) (* (* -1.0 A) (* 2.0 (* A (* C F))))))
(- (* -1.0 (pow B_m 2.0)) (* (* (* -1.0 4.0) A) C)))
(* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5)))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 1.4e-247) {
tmp = pow((-0.5 * (F / C)), 0.5) * pow(2.0, 0.5);
} else if (B_m <= 3e-15) {
tmp = sqrt((-(-8.0) * ((-1.0 * A) * (2.0 * (A * (C * F)))))) / ((-1.0 * pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 1.4e-247) {
tmp = Math.pow((-0.5 * (F / C)), 0.5) * Math.pow(2.0, 0.5);
} else if (B_m <= 3e-15) {
tmp = Math.sqrt((-(-8.0) * ((-1.0 * A) * (2.0 * (A * (C * F)))))) / ((-1.0 * Math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (Math.pow(2.0, 0.5) / B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if B_m <= 1.4e-247: tmp = math.pow((-0.5 * (F / C)), 0.5) * math.pow(2.0, 0.5) elif B_m <= 3e-15: tmp = math.sqrt((-(-8.0) * ((-1.0 * A) * (2.0 * (A * (C * F)))))) / ((-1.0 * math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C)) else: tmp = (-1.0 * (math.pow(2.0, 0.5) / B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (B_m <= 1.4e-247) tmp = Float64((Float64(-0.5 * Float64(F / C)) ^ 0.5) * (2.0 ^ 0.5)); elseif (B_m <= 3e-15) tmp = Float64(sqrt(Float64(Float64(-(-8.0)) * Float64(Float64(-1.0 * A) * Float64(2.0 * Float64(A * Float64(C * F)))))) / Float64(Float64(-1.0 * (B_m ^ 2.0)) - Float64(Float64(Float64(-1.0 * 4.0) * A) * C))); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (B_m <= 1.4e-247)
tmp = ((-0.5 * (F / C)) ^ 0.5) * (2.0 ^ 0.5);
elseif (B_m <= 3e-15)
tmp = sqrt((-(-8.0) * ((-1.0 * A) * (2.0 * (A * (C * F)))))) / ((-1.0 * (B_m ^ 2.0)) - (((-1.0 * 4.0) * A) * C));
else
tmp = (-1.0 * ((2.0 ^ 0.5) / B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[B$95$m, 1.4e-247], N[(N[Power[N[(-0.5 * N[(F / C), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[2.0, 0.5], $MachinePrecision]), $MachinePrecision], If[LessEqual[B$95$m, 3e-15], N[(N[Sqrt[N[((--8.0) * N[(N[(-1.0 * A), $MachinePrecision] * N[(2.0 * N[(A * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(-1.0 * N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(-1.0 * 4.0), $MachinePrecision] * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B\_m \leq 1.4 \cdot 10^{-247}:\\
\;\;\;\;{\left(-0.5 \cdot \frac{F}{C}\right)}^{0.5} \cdot {2}^{0.5}\\
\mathbf{elif}\;B\_m \leq 3 \cdot 10^{-15}:\\
\;\;\;\;\frac{\sqrt{\left(--8\right) \cdot \left(\left(-1 \cdot A\right) \cdot \left(2 \cdot \left(A \cdot \left(C \cdot F\right)\right)\right)\right)}}{-1 \cdot {B\_m}^{2} - \left(\left(-1 \cdot 4\right) \cdot A\right) \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if B < 1.39999999999999993e-247Initial program 14.5%
Taylor expanded in F around -inf
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites3.4%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-/.f6413.0
Applied rewrites13.0%
if 1.39999999999999993e-247 < B < 3e-15Initial program 27.7%
Taylor expanded in C around inf
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6436.0
Applied rewrites36.0%
Taylor expanded in A around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6428.6
Applied rewrites28.6%
if 3e-15 < B Initial program 9.5%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f647.3
Applied rewrites7.3%
Taylor expanded in C around 0
Applied rewrites40.4%
Final simplification21.9%
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(if (<= (pow B_m 2.0) 1e-275)
(* (pow (* -0.5 (/ F C)) 0.5) (pow 2.0 0.5))
(if (<= (pow B_m 2.0) 2e-30)
(/
(sqrt (* -16.0 (* (* (* -1.0 A) A) (* (* -1.0 C) F))))
(- (* -1.0 (pow B_m 2.0)) (* (* (* -1.0 4.0) A) C)))
(* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5)))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (pow(B_m, 2.0) <= 1e-275) {
tmp = pow((-0.5 * (F / C)), 0.5) * pow(2.0, 0.5);
} else if (pow(B_m, 2.0) <= 2e-30) {
tmp = sqrt((-16.0 * (((-1.0 * A) * A) * ((-1.0 * C) * F)))) / ((-1.0 * pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (Math.pow(B_m, 2.0) <= 1e-275) {
tmp = Math.pow((-0.5 * (F / C)), 0.5) * Math.pow(2.0, 0.5);
} else if (Math.pow(B_m, 2.0) <= 2e-30) {
tmp = Math.sqrt((-16.0 * (((-1.0 * A) * A) * ((-1.0 * C) * F)))) / ((-1.0 * Math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C));
} else {
tmp = (-1.0 * (Math.pow(2.0, 0.5) / B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if math.pow(B_m, 2.0) <= 1e-275: tmp = math.pow((-0.5 * (F / C)), 0.5) * math.pow(2.0, 0.5) elif math.pow(B_m, 2.0) <= 2e-30: tmp = math.sqrt((-16.0 * (((-1.0 * A) * A) * ((-1.0 * C) * F)))) / ((-1.0 * math.pow(B_m, 2.0)) - (((-1.0 * 4.0) * A) * C)) else: tmp = (-1.0 * (math.pow(2.0, 0.5) / B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if ((B_m ^ 2.0) <= 1e-275) tmp = Float64((Float64(-0.5 * Float64(F / C)) ^ 0.5) * (2.0 ^ 0.5)); elseif ((B_m ^ 2.0) <= 2e-30) tmp = Float64(sqrt(Float64(-16.0 * Float64(Float64(Float64(-1.0 * A) * A) * Float64(Float64(-1.0 * C) * F)))) / Float64(Float64(-1.0 * (B_m ^ 2.0)) - Float64(Float64(Float64(-1.0 * 4.0) * A) * C))); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if ((B_m ^ 2.0) <= 1e-275)
tmp = ((-0.5 * (F / C)) ^ 0.5) * (2.0 ^ 0.5);
elseif ((B_m ^ 2.0) <= 2e-30)
tmp = sqrt((-16.0 * (((-1.0 * A) * A) * ((-1.0 * C) * F)))) / ((-1.0 * (B_m ^ 2.0)) - (((-1.0 * 4.0) * A) * C));
else
tmp = (-1.0 * ((2.0 ^ 0.5) / B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 1e-275], N[(N[Power[N[(-0.5 * N[(F / C), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[2.0, 0.5], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 2e-30], N[(N[Sqrt[N[(-16.0 * N[(N[(N[(-1.0 * A), $MachinePrecision] * A), $MachinePrecision] * N[(N[(-1.0 * C), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(-1.0 * N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(-1.0 * 4.0), $MachinePrecision] * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;{B\_m}^{2} \leq 10^{-275}:\\
\;\;\;\;{\left(-0.5 \cdot \frac{F}{C}\right)}^{0.5} \cdot {2}^{0.5}\\
\mathbf{elif}\;{B\_m}^{2} \leq 2 \cdot 10^{-30}:\\
\;\;\;\;\frac{\sqrt{-16 \cdot \left(\left(\left(-1 \cdot A\right) \cdot A\right) \cdot \left(\left(-1 \cdot C\right) \cdot F\right)\right)}}{-1 \cdot {B\_m}^{2} - \left(\left(-1 \cdot 4\right) \cdot A\right) \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if (pow.f64 B #s(literal 2 binary64)) < 9.99999999999999934e-276Initial program 13.1%
Taylor expanded in F around -inf
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites5.1%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-/.f6418.0
Applied rewrites18.0%
if 9.99999999999999934e-276 < (pow.f64 B #s(literal 2 binary64)) < 2e-30Initial program 28.0%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6430.0
Applied rewrites30.0%
if 2e-30 < (pow.f64 B #s(literal 2 binary64)) Initial program 13.1%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f647.1
Applied rewrites7.1%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f647.1
Applied rewrites7.1%
Taylor expanded in C around 0
Applied rewrites20.4%
Final simplification21.2%
B_m = (fabs.f64 B) NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. (FPCore (A B_m C F) :precision binary64 (if (<= (pow B_m 2.0) 5e-74) (* (pow (* -0.5 (/ F C)) 0.5) (pow 2.0 0.5)) (* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (pow(B_m, 2.0) <= 5e-74) {
tmp = pow((-0.5 * (F / C)), 0.5) * pow(2.0, 0.5);
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (Math.pow(B_m, 2.0) <= 5e-74) {
tmp = Math.pow((-0.5 * (F / C)), 0.5) * Math.pow(2.0, 0.5);
} else {
tmp = (-1.0 * (Math.pow(2.0, 0.5) / B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if math.pow(B_m, 2.0) <= 5e-74: tmp = math.pow((-0.5 * (F / C)), 0.5) * math.pow(2.0, 0.5) else: tmp = (-1.0 * (math.pow(2.0, 0.5) / B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if ((B_m ^ 2.0) <= 5e-74) tmp = Float64((Float64(-0.5 * Float64(F / C)) ^ 0.5) * (2.0 ^ 0.5)); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if ((B_m ^ 2.0) <= 5e-74)
tmp = ((-0.5 * (F / C)) ^ 0.5) * (2.0 ^ 0.5);
else
tmp = (-1.0 * ((2.0 ^ 0.5) / B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 5e-74], N[(N[Power[N[(-0.5 * N[(F / C), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[2.0, 0.5], $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;{B\_m}^{2} \leq 5 \cdot 10^{-74}:\\
\;\;\;\;{\left(-0.5 \cdot \frac{F}{C}\right)}^{0.5} \cdot {2}^{0.5}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if (pow.f64 B #s(literal 2 binary64)) < 4.99999999999999998e-74Initial program 18.4%
Taylor expanded in F around -inf
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites7.3%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-/.f6420.8
Applied rewrites20.8%
if 4.99999999999999998e-74 < (pow.f64 B #s(literal 2 binary64)) Initial program 12.8%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f648.5
Applied rewrites8.5%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f648.5
Applied rewrites8.5%
Taylor expanded in C around 0
Applied rewrites19.9%
Final simplification20.4%
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(if (<= B_m 1.35e-16)
(*
(pow
(/
(* F (- (+ A C) (pow (fma B_m B_m (pow (- A C) 2.0)) 0.5)))
(- (* B_m B_m) (* 4.0 (* A C))))
0.5)
(* -1.0 (pow 2.0 0.5)))
(* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (B_m <= 1.35e-16) {
tmp = pow(((F * ((A + C) - pow(fma(B_m, B_m, pow((A - C), 2.0)), 0.5))) / ((B_m * B_m) - (4.0 * (A * C)))), 0.5) * (-1.0 * pow(2.0, 0.5));
} else {
tmp = (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
return tmp;
}
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (B_m <= 1.35e-16) tmp = Float64((Float64(Float64(F * Float64(Float64(A + C) - (fma(B_m, B_m, (Float64(A - C) ^ 2.0)) ^ 0.5))) / Float64(Float64(B_m * B_m) - Float64(4.0 * Float64(A * C)))) ^ 0.5) * Float64(-1.0 * (2.0 ^ 0.5))); else tmp = Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)); end return tmp end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[B$95$m, 1.35e-16], N[(N[Power[N[(N[(F * N[(N[(A + C), $MachinePrecision] - N[Power[N[(B$95$m * B$95$m + N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(B$95$m * B$95$m), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] * N[(-1.0 * N[Power[2.0, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B\_m \leq 1.35 \cdot 10^{-16}:\\
\;\;\;\;{\left(\frac{F \cdot \left(\left(A + C\right) - {\left(\mathsf{fma}\left(B\_m, B\_m, {\left(A - C\right)}^{2}\right)\right)}^{0.5}\right)}{B\_m \cdot B\_m - 4 \cdot \left(A \cdot C\right)}\right)}^{0.5} \cdot \left(-1 \cdot {2}^{0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}\\
\end{array}
\end{array}
if B < 1.35e-16Initial program 17.5%
Taylor expanded in F around 0
lower-*.f64N/A
lower-*.f64N/A
Applied rewrites16.6%
if 1.35e-16 < B Initial program 9.4%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f647.2
Applied rewrites7.2%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f647.2
Applied rewrites7.2%
Taylor expanded in C around 0
Applied rewrites39.7%
Final simplification22.0%
B_m = (fabs.f64 B) NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. (FPCore (A B_m C F) :precision binary64 (* (* -1.0 (/ (pow 2.0 0.5) B_m)) (pow (* F (- A (hypot A B_m))) 0.5)))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
return (-1.0 * (pow(2.0, 0.5) / B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
return (-1.0 * (Math.pow(2.0, 0.5) / B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): return (-1.0 * (math.pow(2.0, 0.5) / B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5)
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) return Float64(Float64(-1.0 * Float64((2.0 ^ 0.5) / B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)) end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp = code(A, B_m, C, F)
tmp = (-1.0 * ((2.0 ^ 0.5) / B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := N[(N[(-1.0 * N[(N[Power[2.0, 0.5], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\left(-1 \cdot \frac{{2}^{0.5}}{B\_m}\right) \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}
\end{array}
Initial program 15.6%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6416.7
Applied rewrites16.7%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f6416.7
Applied rewrites16.7%
Taylor expanded in C around 0
Applied rewrites12.2%
Final simplification12.2%
B_m = (fabs.f64 B) NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. (FPCore (A B_m C F) :precision binary64 (* (/ (exp (* (log 2.0) 0.5)) (* -1.0 B_m)) (pow (* F (- A (hypot A B_m))) 0.5)))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
return (exp((log(2.0) * 0.5)) / (-1.0 * B_m)) * pow((F * (A - hypot(A, B_m))), 0.5);
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
return (Math.exp((Math.log(2.0) * 0.5)) / (-1.0 * B_m)) * Math.pow((F * (A - Math.hypot(A, B_m))), 0.5);
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): return (math.exp((math.log(2.0) * 0.5)) / (-1.0 * B_m)) * math.pow((F * (A - math.hypot(A, B_m))), 0.5)
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) return Float64(Float64(exp(Float64(log(2.0) * 0.5)) / Float64(-1.0 * B_m)) * (Float64(F * Float64(A - hypot(A, B_m))) ^ 0.5)) end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp = code(A, B_m, C, F)
tmp = (exp((log(2.0) * 0.5)) / (-1.0 * B_m)) * ((F * (A - hypot(A, B_m))) ^ 0.5);
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := N[(N[(N[Exp[N[(N[Log[2.0], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] / N[(-1.0 * B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(A - N[Sqrt[A ^ 2 + B$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\frac{e^{\log 2 \cdot 0.5}}{-1 \cdot B\_m} \cdot {\left(F \cdot \left(A - \mathsf{hypot}\left(A, B\_m\right)\right)\right)}^{0.5}
\end{array}
Initial program 15.6%
Taylor expanded in C around inf
lower--.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6416.7
Applied rewrites16.7%
Taylor expanded in C around 0
lower-/.f64N/A
lower-fma.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift--.f6416.7
Applied rewrites16.7%
Taylor expanded in C around 0
Applied rewrites12.2%
lift-pow.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6412.2
Applied rewrites12.2%
Final simplification12.2%
B_m = (fabs.f64 B) NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. (FPCore (A B_m C F) :precision binary64 (if (<= A -1.15e+146) (* -1.0 (* (* -1.0 (pow (* A F) 0.5)) (/ -2.0 B_m))) (* (/ (exp (* (log 2.0) 0.5)) (* -1.0 B_m)) (pow (* F (* -1.0 B_m)) 0.5))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (A <= -1.15e+146) {
tmp = -1.0 * ((-1.0 * pow((A * F), 0.5)) * (-2.0 / B_m));
} else {
tmp = (exp((log(2.0) * 0.5)) / (-1.0 * B_m)) * pow((F * (-1.0 * B_m)), 0.5);
}
return tmp;
}
B_m = private
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
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_m, c, f)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: tmp
if (a <= (-1.15d+146)) then
tmp = (-1.0d0) * (((-1.0d0) * ((a * f) ** 0.5d0)) * ((-2.0d0) / b_m))
else
tmp = (exp((log(2.0d0) * 0.5d0)) / ((-1.0d0) * b_m)) * ((f * ((-1.0d0) * b_m)) ** 0.5d0)
end if
code = tmp
end function
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (A <= -1.15e+146) {
tmp = -1.0 * ((-1.0 * Math.pow((A * F), 0.5)) * (-2.0 / B_m));
} else {
tmp = (Math.exp((Math.log(2.0) * 0.5)) / (-1.0 * B_m)) * Math.pow((F * (-1.0 * B_m)), 0.5);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if A <= -1.15e+146: tmp = -1.0 * ((-1.0 * math.pow((A * F), 0.5)) * (-2.0 / B_m)) else: tmp = (math.exp((math.log(2.0) * 0.5)) / (-1.0 * B_m)) * math.pow((F * (-1.0 * B_m)), 0.5) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (A <= -1.15e+146) tmp = Float64(-1.0 * Float64(Float64(-1.0 * (Float64(A * F) ^ 0.5)) * Float64(-2.0 / B_m))); else tmp = Float64(Float64(exp(Float64(log(2.0) * 0.5)) / Float64(-1.0 * B_m)) * (Float64(F * Float64(-1.0 * B_m)) ^ 0.5)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (A <= -1.15e+146)
tmp = -1.0 * ((-1.0 * ((A * F) ^ 0.5)) * (-2.0 / B_m));
else
tmp = (exp((log(2.0) * 0.5)) / (-1.0 * B_m)) * ((F * (-1.0 * B_m)) ^ 0.5);
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[A, -1.15e+146], N[(-1.0 * N[(N[(-1.0 * N[Power[N[(A * F), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(-2.0 / B$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[N[(N[Log[2.0], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] / N[(-1.0 * B$95$m), $MachinePrecision]), $MachinePrecision] * N[Power[N[(F * N[(-1.0 * B$95$m), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;A \leq -1.15 \cdot 10^{+146}:\\
\;\;\;\;-1 \cdot \left(\left(-1 \cdot {\left(A \cdot F\right)}^{0.5}\right) \cdot \frac{-2}{B\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\log 2 \cdot 0.5}}{-1 \cdot B\_m} \cdot {\left(F \cdot \left(-1 \cdot B\_m\right)\right)}^{0.5}\\
\end{array}
\end{array}
if A < -1.15e146Initial program 1.8%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
pow1/2N/A
lower-pow.f64N/A
pow1/2N/A
lower-pow.f64N/A
Applied rewrites4.8%
Taylor expanded in A around 0
lower-*.f644.1
Applied rewrites4.1%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-*.f64N/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f6412.2
Applied rewrites12.2%
if -1.15e146 < A Initial program 17.5%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
pow1/2N/A
lower-pow.f64N/A
pow1/2N/A
lower-pow.f64N/A
Applied rewrites8.1%
Taylor expanded in A around 0
lower-*.f6411.0
Applied rewrites11.0%
lift-pow.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6411.0
Applied rewrites11.0%
Final simplification11.2%
B_m = (fabs.f64 B) NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. (FPCore (A B_m C F) :precision binary64 (if (<= F -3.2e+68) (* -1.0 (* (* -1.0 A) (* -2.0 (* (pow (/ F A) 0.5) (/ -1.0 B_m))))) (* -1.0 (* (* -1.0 (pow (* A F) 0.5)) (/ -2.0 B_m)))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double tmp;
if (F <= -3.2e+68) {
tmp = -1.0 * ((-1.0 * A) * (-2.0 * (pow((F / A), 0.5) * (-1.0 / B_m))));
} else {
tmp = -1.0 * ((-1.0 * pow((A * F), 0.5)) * (-2.0 / B_m));
}
return tmp;
}
B_m = private
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
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_m, c, f)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: tmp
if (f <= (-3.2d+68)) then
tmp = (-1.0d0) * (((-1.0d0) * a) * ((-2.0d0) * (((f / a) ** 0.5d0) * ((-1.0d0) / b_m))))
else
tmp = (-1.0d0) * (((-1.0d0) * ((a * f) ** 0.5d0)) * ((-2.0d0) / b_m))
end if
code = tmp
end function
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
double tmp;
if (F <= -3.2e+68) {
tmp = -1.0 * ((-1.0 * A) * (-2.0 * (Math.pow((F / A), 0.5) * (-1.0 / B_m))));
} else {
tmp = -1.0 * ((-1.0 * Math.pow((A * F), 0.5)) * (-2.0 / B_m));
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if F <= -3.2e+68: tmp = -1.0 * ((-1.0 * A) * (-2.0 * (math.pow((F / A), 0.5) * (-1.0 / B_m)))) else: tmp = -1.0 * ((-1.0 * math.pow((A * F), 0.5)) * (-2.0 / B_m)) return tmp
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (F <= -3.2e+68) tmp = Float64(-1.0 * Float64(Float64(-1.0 * A) * Float64(-2.0 * Float64((Float64(F / A) ^ 0.5) * Float64(-1.0 / B_m))))); else tmp = Float64(-1.0 * Float64(Float64(-1.0 * (Float64(A * F) ^ 0.5)) * Float64(-2.0 / B_m))); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (F <= -3.2e+68)
tmp = -1.0 * ((-1.0 * A) * (-2.0 * (((F / A) ^ 0.5) * (-1.0 / B_m))));
else
tmp = -1.0 * ((-1.0 * ((A * F) ^ 0.5)) * (-2.0 / B_m));
end
tmp_2 = tmp;
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := If[LessEqual[F, -3.2e+68], N[(-1.0 * N[(N[(-1.0 * A), $MachinePrecision] * N[(-2.0 * N[(N[Power[N[(F / A), $MachinePrecision], 0.5], $MachinePrecision] * N[(-1.0 / B$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(N[(-1.0 * N[Power[N[(A * F), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(-2.0 / B$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;F \leq -3.2 \cdot 10^{+68}:\\
\;\;\;\;-1 \cdot \left(\left(-1 \cdot A\right) \cdot \left(-2 \cdot \left({\left(\frac{F}{A}\right)}^{0.5} \cdot \frac{-1}{B\_m}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \left(\left(-1 \cdot {\left(A \cdot F\right)}^{0.5}\right) \cdot \frac{-2}{B\_m}\right)\\
\end{array}
\end{array}
if F < -3.19999999999999994e68Initial program 11.8%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
pow1/2N/A
lower-pow.f64N/A
pow1/2N/A
lower-pow.f64N/A
Applied rewrites9.0%
Taylor expanded in A around 0
lower-*.f648.2
Applied rewrites8.2%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites2.8%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lift-pow.f64N/A
lift-/.f64N/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-/.f642.8
Applied rewrites2.8%
if -3.19999999999999994e68 < F Initial program 17.9%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
pow1/2N/A
lower-pow.f64N/A
pow1/2N/A
lower-pow.f64N/A
Applied rewrites6.9%
Taylor expanded in A around 0
lower-*.f6411.3
Applied rewrites11.3%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-*.f64N/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f643.7
Applied rewrites3.7%
Final simplification3.3%
B_m = (fabs.f64 B) NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. (FPCore (A B_m C F) :precision binary64 (* -1.0 (* (* -1.0 A) (* -2.0 (* (pow (/ F A) 0.5) (/ -1.0 B_m))))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
return -1.0 * ((-1.0 * A) * (-2.0 * (pow((F / A), 0.5) * (-1.0 / B_m))));
}
B_m = private
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
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_m, c, f)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
code = (-1.0d0) * (((-1.0d0) * a) * ((-2.0d0) * (((f / a) ** 0.5d0) * ((-1.0d0) / b_m))))
end function
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
return -1.0 * ((-1.0 * A) * (-2.0 * (Math.pow((F / A), 0.5) * (-1.0 / B_m))));
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): return -1.0 * ((-1.0 * A) * (-2.0 * (math.pow((F / A), 0.5) * (-1.0 / B_m))))
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) return Float64(-1.0 * Float64(Float64(-1.0 * A) * Float64(-2.0 * Float64((Float64(F / A) ^ 0.5) * Float64(-1.0 / B_m))))) end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp = code(A, B_m, C, F)
tmp = -1.0 * ((-1.0 * A) * (-2.0 * (((F / A) ^ 0.5) * (-1.0 / B_m))));
end
B_m = N[Abs[B], $MachinePrecision] NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function. code[A_, B$95$m_, C_, F_] := N[(-1.0 * N[(N[(-1.0 * A), $MachinePrecision] * N[(-2.0 * N[(N[Power[N[(F / A), $MachinePrecision], 0.5], $MachinePrecision] * N[(-1.0 / B$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
-1 \cdot \left(\left(-1 \cdot A\right) \cdot \left(-2 \cdot \left({\left(\frac{F}{A}\right)}^{0.5} \cdot \frac{-1}{B\_m}\right)\right)\right)
\end{array}
Initial program 15.6%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
pow1/2N/A
lower-pow.f64N/A
pow1/2N/A
lower-pow.f64N/A
Applied rewrites7.7%
Taylor expanded in A around 0
lower-*.f6410.1
Applied rewrites10.1%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites2.4%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lift-pow.f64N/A
lift-/.f64N/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-/.f642.6
Applied rewrites2.6%
Final simplification2.6%
herbie shell --seed 2025064
(FPCore (A B C F)
:name "ABCF->ab-angle b"
:precision binary64
(/ (- (sqrt (* (* 2.0 (* (- (pow B 2.0) (* (* 4.0 A) C)) F)) (- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))) (- (pow B 2.0) (* (* 4.0 A) C))))