
(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}
Herbie found 11 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}
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (sqrt (* (/ F C) -1.0))))
(t_1 (* (* 4.0 A) C))
(t_2 (- (pow B 2.0) t_1))
(t_3
(/
(sqrt
(*
(* 2.0 (* t_2 F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))
(- t_2))))
(if (<= t_3 (- INFINITY))
t_0
(if (<= t_3 -1e-197)
(/
(sqrt (* (* 2.0 (* (- (* B B) t_1) F)) (- (+ A C) (hypot (- A C) B))))
(+ (* (- B) B) t_1))
(if (<= t_3 0.0)
t_0
(if (<= t_3 INFINITY)
(sqrt
(*
(/
(* F (- (+ A C) (hypot B (- A C))))
(- (* B B) (* 4.0 (* A C))))
2.0))
(- (sqrt (* (* (/ F B) (/ (- A (hypot A B)) B)) 2.0)))))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = -sqrt(((F / C) * -1.0));
double t_1 = (4.0 * A) * C;
double t_2 = pow(B, 2.0) - t_1;
double t_3 = sqrt(((2.0 * (t_2 * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / -t_2;
double tmp;
if (t_3 <= -((double) INFINITY)) {
tmp = t_0;
} else if (t_3 <= -1e-197) {
tmp = sqrt(((2.0 * (((B * B) - t_1) * F)) * ((A + C) - hypot((A - C), B)))) / ((-B * B) + t_1);
} else if (t_3 <= 0.0) {
tmp = t_0;
} else if (t_3 <= ((double) INFINITY)) {
tmp = sqrt((((F * ((A + C) - hypot(B, (A - C)))) / ((B * B) - (4.0 * (A * C)))) * 2.0));
} else {
tmp = -sqrt((((F / B) * ((A - hypot(A, B)) / B)) * 2.0));
}
return tmp;
}
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double t_0 = -Math.sqrt(((F / C) * -1.0));
double t_1 = (4.0 * A) * C;
double t_2 = Math.pow(B, 2.0) - t_1;
double t_3 = Math.sqrt(((2.0 * (t_2 * F)) * ((A + C) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / -t_2;
double tmp;
if (t_3 <= -Double.POSITIVE_INFINITY) {
tmp = t_0;
} else if (t_3 <= -1e-197) {
tmp = Math.sqrt(((2.0 * (((B * B) - t_1) * F)) * ((A + C) - Math.hypot((A - C), B)))) / ((-B * B) + t_1);
} else if (t_3 <= 0.0) {
tmp = t_0;
} else if (t_3 <= Double.POSITIVE_INFINITY) {
tmp = Math.sqrt((((F * ((A + C) - Math.hypot(B, (A - C)))) / ((B * B) - (4.0 * (A * C)))) * 2.0));
} else {
tmp = -Math.sqrt((((F / B) * ((A - Math.hypot(A, B)) / B)) * 2.0));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): t_0 = -math.sqrt(((F / C) * -1.0)) t_1 = (4.0 * A) * C t_2 = math.pow(B, 2.0) - t_1 t_3 = math.sqrt(((2.0 * (t_2 * F)) * ((A + C) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / -t_2 tmp = 0 if t_3 <= -math.inf: tmp = t_0 elif t_3 <= -1e-197: tmp = math.sqrt(((2.0 * (((B * B) - t_1) * F)) * ((A + C) - math.hypot((A - C), B)))) / ((-B * B) + t_1) elif t_3 <= 0.0: tmp = t_0 elif t_3 <= math.inf: tmp = math.sqrt((((F * ((A + C) - math.hypot(B, (A - C)))) / ((B * B) - (4.0 * (A * C)))) * 2.0)) else: tmp = -math.sqrt((((F / B) * ((A - math.hypot(A, B)) / B)) * 2.0)) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(-sqrt(Float64(Float64(F / C) * -1.0))) t_1 = Float64(Float64(4.0 * A) * C) t_2 = Float64((B ^ 2.0) - t_1) t_3 = Float64(sqrt(Float64(Float64(2.0 * Float64(t_2 * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))) / Float64(-t_2)) tmp = 0.0 if (t_3 <= Float64(-Inf)) tmp = t_0; elseif (t_3 <= -1e-197) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64(Float64(B * B) - t_1) * F)) * Float64(Float64(A + C) - hypot(Float64(A - C), B)))) / Float64(Float64(Float64(-B) * B) + t_1)); elseif (t_3 <= 0.0) tmp = t_0; elseif (t_3 <= Inf) tmp = sqrt(Float64(Float64(Float64(F * Float64(Float64(A + C) - hypot(B, Float64(A - C)))) / Float64(Float64(B * B) - Float64(4.0 * Float64(A * C)))) * 2.0)); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - hypot(A, B)) / B)) * 2.0))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
t_0 = -sqrt(((F / C) * -1.0));
t_1 = (4.0 * A) * C;
t_2 = (B ^ 2.0) - t_1;
t_3 = sqrt(((2.0 * (t_2 * F)) * ((A + C) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / -t_2;
tmp = 0.0;
if (t_3 <= -Inf)
tmp = t_0;
elseif (t_3 <= -1e-197)
tmp = sqrt(((2.0 * (((B * B) - t_1) * F)) * ((A + C) - hypot((A - C), B)))) / ((-B * B) + t_1);
elseif (t_3 <= 0.0)
tmp = t_0;
elseif (t_3 <= Inf)
tmp = sqrt((((F * ((A + C) - hypot(B, (A - C)))) / ((B * B) - (4.0 * (A * C)))) * 2.0));
else
tmp = -sqrt((((F / B) * ((A - hypot(A, B)) / B)) * 2.0));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = (-N[Sqrt[N[(N[(F / C), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[B, 2.0], $MachinePrecision] - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(N[(2.0 * N[(t$95$2 * 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$2)), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], t$95$0, If[LessEqual[t$95$3, -1e-197], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[(B * B), $MachinePrecision] - t$95$1), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(A - C), $MachinePrecision] ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], t$95$0, If[LessEqual[t$95$3, Infinity], N[Sqrt[N[(N[(N[(F * N[(N[(A + C), $MachinePrecision] - N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision], (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - N[Sqrt[A ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]]]]]]]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := -\sqrt{\frac{F}{C} \cdot -1}\\
t_1 := \left(4 \cdot A\right) \cdot C\\
t_2 := {B}^{2} - t\_1\\
t_3 := \frac{\sqrt{\left(2 \cdot \left(t\_2 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{-t\_2}\\
\mathbf{if}\;t\_3 \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_3 \leq -1 \cdot 10^{-197}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left(B \cdot B - t\_1\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(A - C, B\right)\right)}}{\left(-B\right) \cdot B + t\_1}\\
\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_3 \leq \infty:\\
\;\;\;\;\sqrt{\frac{F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)} \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - \mathsf{hypot}\left(A, B\right)}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -inf.0 or -9.9999999999999999e-198 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < 0.0Initial program 3.3%
Taylor expanded in A around -inf
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f640.0
Applied rewrites0.0%
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6424.4
Applied rewrites24.4%
if -inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -9.9999999999999999e-198Initial program 95.8%
Applied rewrites95.8%
if 0.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < +inf.0Initial program 41.8%
Taylor expanded in F around -inf
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
Applied rewrites64.7%
if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) Initial program 0.0%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites3.4%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f643.1
Applied rewrites3.1%
Applied rewrites41.6%
Final simplification46.4%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (sqrt (* (/ F C) -1.0))))
(t_1 (* (* 4.0 A) C))
(t_2 (- (pow B 2.0) t_1))
(t_3
(/
(sqrt
(*
(* 2.0 (* t_2 F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))
(- t_2))))
(if (<= t_3 (- INFINITY))
t_0
(if (<= t_3 -1e-197)
(* (/ (sqrt 2.0) (- B)) (sqrt (* F (- A (sqrt (fma A A (* B B)))))))
(if (<= t_3 0.0)
t_0
(if (<= t_3 INFINITY)
(/ (sqrt (* -16.0 (* (* A A) (* C F)))) (+ (* (- B) B) t_1))
(- (sqrt (* (* (/ F B) (/ (- A B) B)) 2.0)))))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = -sqrt(((F / C) * -1.0));
double t_1 = (4.0 * A) * C;
double t_2 = pow(B, 2.0) - t_1;
double t_3 = sqrt(((2.0 * (t_2 * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / -t_2;
double tmp;
if (t_3 <= -((double) INFINITY)) {
tmp = t_0;
} else if (t_3 <= -1e-197) {
tmp = (sqrt(2.0) / -B) * sqrt((F * (A - sqrt(fma(A, A, (B * B))))));
} else if (t_3 <= 0.0) {
tmp = t_0;
} else if (t_3 <= ((double) INFINITY)) {
tmp = sqrt((-16.0 * ((A * A) * (C * F)))) / ((-B * B) + t_1);
} else {
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(-sqrt(Float64(Float64(F / C) * -1.0))) t_1 = Float64(Float64(4.0 * A) * C) t_2 = Float64((B ^ 2.0) - t_1) t_3 = Float64(sqrt(Float64(Float64(2.0 * Float64(t_2 * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))) / Float64(-t_2)) tmp = 0.0 if (t_3 <= Float64(-Inf)) tmp = t_0; elseif (t_3 <= -1e-197) tmp = Float64(Float64(sqrt(2.0) / Float64(-B)) * sqrt(Float64(F * Float64(A - sqrt(fma(A, A, Float64(B * B))))))); elseif (t_3 <= 0.0) tmp = t_0; elseif (t_3 <= Inf) tmp = Float64(sqrt(Float64(-16.0 * Float64(Float64(A * A) * Float64(C * F)))) / Float64(Float64(Float64(-B) * B) + t_1)); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - B) / B)) * 2.0))); end return tmp end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = (-N[Sqrt[N[(N[(F / C), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[B, 2.0], $MachinePrecision] - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(N[(2.0 * N[(t$95$2 * 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$2)), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], t$95$0, If[LessEqual[t$95$3, -1e-197], N[(N[(N[Sqrt[2.0], $MachinePrecision] / (-B)), $MachinePrecision] * N[Sqrt[N[(F * N[(A - N[Sqrt[N[(A * A + N[(B * B), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], t$95$0, If[LessEqual[t$95$3, Infinity], N[(N[Sqrt[N[(-16.0 * N[(N[(A * A), $MachinePrecision] * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - B), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]]]]]]]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := -\sqrt{\frac{F}{C} \cdot -1}\\
t_1 := \left(4 \cdot A\right) \cdot C\\
t_2 := {B}^{2} - t\_1\\
t_3 := \frac{\sqrt{\left(2 \cdot \left(t\_2 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{-t\_2}\\
\mathbf{if}\;t\_3 \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_3 \leq -1 \cdot 10^{-197}:\\
\;\;\;\;\frac{\sqrt{2}}{-B} \cdot \sqrt{F \cdot \left(A - \sqrt{\mathsf{fma}\left(A, A, B \cdot B\right)}\right)}\\
\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_3 \leq \infty:\\
\;\;\;\;\frac{\sqrt{-16 \cdot \left(\left(A \cdot A\right) \cdot \left(C \cdot F\right)\right)}}{\left(-B\right) \cdot B + t\_1}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - B}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -inf.0 or -9.9999999999999999e-198 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < 0.0Initial program 3.3%
Taylor expanded in A around -inf
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f640.0
Applied rewrites0.0%
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6424.4
Applied rewrites24.4%
if -inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -9.9999999999999999e-198Initial program 95.8%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6433.1
Applied rewrites33.1%
lift-hypot.f64N/A
pow2N/A
pow2N/A
lower-sqrt.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6433.1
Applied rewrites33.1%
if 0.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < +inf.0Initial program 41.8%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6427.8
Applied rewrites27.8%
lift-pow.f64N/A
pow2N/A
lift-*.f6427.8
Applied rewrites27.8%
if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) Initial program 0.0%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites3.4%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f643.1
Applied rewrites3.1%
Applied rewrites41.6%
Taylor expanded in A around 0
Applied rewrites22.6%
Final simplification25.4%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (* (* 4.0 A) C)) (t_1 (- (pow B 2.0) t_0)))
(if (<= B 9.2e-95)
(/ (sqrt (* (* 2.0 (* t_1 F)) (* 2.0 A))) (- t_1))
(if (<= B 1.7e-24)
(/
(sqrt
(*
2.0
(* F (* (- (+ A C) (hypot B (- A C))) (- (* B B) (* 4.0 (* A C)))))))
(- (* A (- (/ (* B B) A) (* 4.0 C)))))
(if (<= B 7.5e+48)
(/
(sqrt
(*
(* 2.0 (* (- (* B B) t_0) F))
(+ (+ A (* -0.5 (/ (* B B) C))) A)))
(+ (* (- B) B) t_0))
(- (sqrt (* (* (/ F B) (/ (- A (hypot A B)) B)) 2.0))))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double t_1 = pow(B, 2.0) - t_0;
double tmp;
if (B <= 9.2e-95) {
tmp = sqrt(((2.0 * (t_1 * F)) * (2.0 * A))) / -t_1;
} else if (B <= 1.7e-24) {
tmp = sqrt((2.0 * (F * (((A + C) - hypot(B, (A - C))) * ((B * B) - (4.0 * (A * C))))))) / -(A * (((B * B) / A) - (4.0 * C)));
} else if (B <= 7.5e+48) {
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = -sqrt((((F / B) * ((A - hypot(A, B)) / B)) * 2.0));
}
return tmp;
}
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double t_1 = Math.pow(B, 2.0) - t_0;
double tmp;
if (B <= 9.2e-95) {
tmp = Math.sqrt(((2.0 * (t_1 * F)) * (2.0 * A))) / -t_1;
} else if (B <= 1.7e-24) {
tmp = Math.sqrt((2.0 * (F * (((A + C) - Math.hypot(B, (A - C))) * ((B * B) - (4.0 * (A * C))))))) / -(A * (((B * B) / A) - (4.0 * C)));
} else if (B <= 7.5e+48) {
tmp = Math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = -Math.sqrt((((F / B) * ((A - Math.hypot(A, B)) / B)) * 2.0));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): t_0 = (4.0 * A) * C t_1 = math.pow(B, 2.0) - t_0 tmp = 0 if B <= 9.2e-95: tmp = math.sqrt(((2.0 * (t_1 * F)) * (2.0 * A))) / -t_1 elif B <= 1.7e-24: tmp = math.sqrt((2.0 * (F * (((A + C) - math.hypot(B, (A - C))) * ((B * B) - (4.0 * (A * C))))))) / -(A * (((B * B) / A) - (4.0 * C))) elif B <= 7.5e+48: tmp = math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0) else: tmp = -math.sqrt((((F / B) * ((A - math.hypot(A, B)) / B)) * 2.0)) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(Float64(4.0 * A) * C) t_1 = Float64((B ^ 2.0) - t_0) tmp = 0.0 if (B <= 9.2e-95) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(t_1 * F)) * Float64(2.0 * A))) / Float64(-t_1)); elseif (B <= 1.7e-24) tmp = Float64(sqrt(Float64(2.0 * Float64(F * Float64(Float64(Float64(A + C) - hypot(B, Float64(A - C))) * Float64(Float64(B * B) - Float64(4.0 * Float64(A * C))))))) / Float64(-Float64(A * Float64(Float64(Float64(B * B) / A) - Float64(4.0 * C))))); elseif (B <= 7.5e+48) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64(Float64(B * B) - t_0) * F)) * Float64(Float64(A + Float64(-0.5 * Float64(Float64(B * B) / C))) + A))) / Float64(Float64(Float64(-B) * B) + t_0)); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - hypot(A, B)) / B)) * 2.0))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (4.0 * A) * C;
t_1 = (B ^ 2.0) - t_0;
tmp = 0.0;
if (B <= 9.2e-95)
tmp = sqrt(((2.0 * (t_1 * F)) * (2.0 * A))) / -t_1;
elseif (B <= 1.7e-24)
tmp = sqrt((2.0 * (F * (((A + C) - hypot(B, (A - C))) * ((B * B) - (4.0 * (A * C))))))) / -(A * (((B * B) / A) - (4.0 * C)));
elseif (B <= 7.5e+48)
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
else
tmp = -sqrt((((F / B) * ((A - hypot(A, B)) / B)) * 2.0));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[B, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[B, 9.2e-95], N[(N[Sqrt[N[(N[(2.0 * N[(t$95$1 * F), $MachinePrecision]), $MachinePrecision] * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-t$95$1)), $MachinePrecision], If[LessEqual[B, 1.7e-24], N[(N[Sqrt[N[(2.0 * N[(F * N[(N[(N[(A + C), $MachinePrecision] - N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-N[(A * N[(N[(N[(B * B), $MachinePrecision] / A), $MachinePrecision] - N[(4.0 * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])), $MachinePrecision], If[LessEqual[B, 7.5e+48], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[(B * B), $MachinePrecision] - t$95$0), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + N[(-0.5 * N[(N[(B * B), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - N[Sqrt[A ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]]]]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := \left(4 \cdot A\right) \cdot C\\
t_1 := {B}^{2} - t\_0\\
\mathbf{if}\;B \leq 9.2 \cdot 10^{-95}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(t\_1 \cdot F\right)\right) \cdot \left(2 \cdot A\right)}}{-t\_1}\\
\mathbf{elif}\;B \leq 1.7 \cdot 10^{-24}:\\
\;\;\;\;\frac{\sqrt{2 \cdot \left(F \cdot \left(\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right)\right)\right)}}{-A \cdot \left(\frac{B \cdot B}{A} - 4 \cdot C\right)}\\
\mathbf{elif}\;B \leq 7.5 \cdot 10^{+48}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left(B \cdot B - t\_0\right) \cdot F\right)\right) \cdot \left(\left(A + -0.5 \cdot \frac{B \cdot B}{C}\right) + A\right)}}{\left(-B\right) \cdot B + t\_0}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - \mathsf{hypot}\left(A, B\right)}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if B < 9.19999999999999997e-95Initial program 22.8%
Taylor expanded in A around -inf
lower-*.f6422.1
Applied rewrites22.1%
if 9.19999999999999997e-95 < B < 1.69999999999999996e-24Initial program 34.4%
Taylor expanded in F around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lift-+.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
lift--.f64N/A
Applied rewrites41.2%
Taylor expanded in A around inf
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lower-*.f6441.2
Applied rewrites41.2%
if 1.69999999999999996e-24 < B < 7.5000000000000006e48Initial program 25.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-*.f6437.1
Applied rewrites37.1%
lift-pow.f64N/A
pow2N/A
lift-*.f6437.1
lift-pow.f64N/A
pow2N/A
lift-*.f6437.1
Applied rewrites37.1%
if 7.5000000000000006e48 < B Initial program 9.5%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites18.9%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f6418.9
Applied rewrites18.9%
Applied rewrites55.2%
Final simplification31.5%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (* (* 4.0 A) C)))
(if (<= (pow B 2.0) 1e+98)
(/
(sqrt
(* (* 2.0 (* (- (* B B) t_0) F)) (+ (+ A (* -0.5 (/ (* B B) C))) A)))
(+ (* (- B) B) t_0))
(- (sqrt (* (* (/ F B) (/ (- A (hypot A B)) B)) 2.0))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (pow(B, 2.0) <= 1e+98) {
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = -sqrt((((F / B) * ((A - hypot(A, B)) / B)) * 2.0));
}
return tmp;
}
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (Math.pow(B, 2.0) <= 1e+98) {
tmp = Math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = -Math.sqrt((((F / B) * ((A - Math.hypot(A, B)) / B)) * 2.0));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): t_0 = (4.0 * A) * C tmp = 0 if math.pow(B, 2.0) <= 1e+98: tmp = math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0) else: tmp = -math.sqrt((((F / B) * ((A - math.hypot(A, B)) / B)) * 2.0)) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(Float64(4.0 * A) * C) tmp = 0.0 if ((B ^ 2.0) <= 1e+98) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64(Float64(B * B) - t_0) * F)) * Float64(Float64(A + Float64(-0.5 * Float64(Float64(B * B) / C))) + A))) / Float64(Float64(Float64(-B) * B) + t_0)); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - hypot(A, B)) / B)) * 2.0))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (4.0 * A) * C;
tmp = 0.0;
if ((B ^ 2.0) <= 1e+98)
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
else
tmp = -sqrt((((F / B) * ((A - hypot(A, B)) / B)) * 2.0));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 1e+98], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[(B * B), $MachinePrecision] - t$95$0), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + N[(-0.5 * N[(N[(B * B), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - N[Sqrt[A ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := \left(4 \cdot A\right) \cdot C\\
\mathbf{if}\;{B}^{2} \leq 10^{+98}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left(B \cdot B - t\_0\right) \cdot F\right)\right) \cdot \left(\left(A + -0.5 \cdot \frac{B \cdot B}{C}\right) + A\right)}}{\left(-B\right) \cdot B + t\_0}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - \mathsf{hypot}\left(A, B\right)}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if (pow.f64 B #s(literal 2 binary64)) < 9.99999999999999998e97Initial program 26.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-*.f6428.5
Applied rewrites28.5%
lift-pow.f64N/A
pow2N/A
lift-*.f6428.5
lift-pow.f64N/A
pow2N/A
lift-*.f6428.5
Applied rewrites28.5%
if 9.99999999999999998e97 < (pow.f64 B #s(literal 2 binary64)) Initial program 12.0%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites21.0%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f6417.6
Applied rewrites17.6%
Applied rewrites54.4%
Final simplification39.1%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (* (* 4.0 A) C)))
(if (<= B 9.5e+49)
(/
(sqrt
(* (* 2.0 (* (- (* B B) t_0) F)) (+ (+ A (* -0.5 (/ (* B B) C))) A)))
(+ (* (- B) B) t_0))
(if (<= B 1.6e+123)
(- (sqrt (* (/ (* F (- A (hypot A B))) (* B B)) 2.0)))
(- (sqrt (* (* (/ F B) (/ (- A B) B)) 2.0)))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (B <= 9.5e+49) {
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else if (B <= 1.6e+123) {
tmp = -sqrt((((F * (A - hypot(A, B))) / (B * B)) * 2.0));
} else {
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (B <= 9.5e+49) {
tmp = Math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else if (B <= 1.6e+123) {
tmp = -Math.sqrt((((F * (A - Math.hypot(A, B))) / (B * B)) * 2.0));
} else {
tmp = -Math.sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): t_0 = (4.0 * A) * C tmp = 0 if B <= 9.5e+49: tmp = math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0) elif B <= 1.6e+123: tmp = -math.sqrt((((F * (A - math.hypot(A, B))) / (B * B)) * 2.0)) else: tmp = -math.sqrt((((F / B) * ((A - B) / B)) * 2.0)) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(Float64(4.0 * A) * C) tmp = 0.0 if (B <= 9.5e+49) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64(Float64(B * B) - t_0) * F)) * Float64(Float64(A + Float64(-0.5 * Float64(Float64(B * B) / C))) + A))) / Float64(Float64(Float64(-B) * B) + t_0)); elseif (B <= 1.6e+123) tmp = Float64(-sqrt(Float64(Float64(Float64(F * Float64(A - hypot(A, B))) / Float64(B * B)) * 2.0))); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - B) / B)) * 2.0))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (4.0 * A) * C;
tmp = 0.0;
if (B <= 9.5e+49)
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
elseif (B <= 1.6e+123)
tmp = -sqrt((((F * (A - hypot(A, B))) / (B * B)) * 2.0));
else
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, If[LessEqual[B, 9.5e+49], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[(B * B), $MachinePrecision] - t$95$0), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + N[(-0.5 * N[(N[(B * B), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[B, 1.6e+123], (-N[Sqrt[N[(N[(N[(F * N[(A - N[Sqrt[A ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(B * B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - B), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := \left(4 \cdot A\right) \cdot C\\
\mathbf{if}\;B \leq 9.5 \cdot 10^{+49}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left(B \cdot B - t\_0\right) \cdot F\right)\right) \cdot \left(\left(A + -0.5 \cdot \frac{B \cdot B}{C}\right) + A\right)}}{\left(-B\right) \cdot B + t\_0}\\
\mathbf{elif}\;B \leq 1.6 \cdot 10^{+123}:\\
\;\;\;\;-\sqrt{\frac{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}{B \cdot B} \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - B}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if B < 9.49999999999999969e49Initial program 23.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-*.f6422.3
Applied rewrites22.3%
lift-pow.f64N/A
pow2N/A
lift-*.f6422.3
lift-pow.f64N/A
pow2N/A
lift-*.f6422.3
Applied rewrites22.3%
if 9.49999999999999969e49 < B < 1.60000000000000002e123Initial program 30.5%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites58.9%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f6459.0
Applied rewrites59.0%
if 1.60000000000000002e123 < B Initial program 2.7%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites5.8%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f645.8
Applied rewrites5.8%
Applied rewrites53.8%
Taylor expanded in A around 0
Applied rewrites53.6%
Final simplification29.6%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (* (* 4.0 A) C)))
(if (<= B 9.5e+49)
(/
(sqrt
(* (* 2.0 (* (- (* B B) t_0) F)) (+ (+ A (* -0.5 (/ (* B B) C))) A)))
(+ (* (- B) B) t_0))
(* (/ (sqrt 2.0) (- B)) (sqrt (* F (- A (hypot A B))))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (B <= 9.5e+49) {
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = (sqrt(2.0) / -B) * sqrt((F * (A - hypot(A, B))));
}
return tmp;
}
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (B <= 9.5e+49) {
tmp = Math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = (Math.sqrt(2.0) / -B) * Math.sqrt((F * (A - Math.hypot(A, B))));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): t_0 = (4.0 * A) * C tmp = 0 if B <= 9.5e+49: tmp = math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0) else: tmp = (math.sqrt(2.0) / -B) * math.sqrt((F * (A - math.hypot(A, B)))) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(Float64(4.0 * A) * C) tmp = 0.0 if (B <= 9.5e+49) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64(Float64(B * B) - t_0) * F)) * Float64(Float64(A + Float64(-0.5 * Float64(Float64(B * B) / C))) + A))) / Float64(Float64(Float64(-B) * B) + t_0)); else tmp = Float64(Float64(sqrt(2.0) / Float64(-B)) * sqrt(Float64(F * Float64(A - hypot(A, B))))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (4.0 * A) * C;
tmp = 0.0;
if (B <= 9.5e+49)
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
else
tmp = (sqrt(2.0) / -B) * sqrt((F * (A - hypot(A, B))));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, If[LessEqual[B, 9.5e+49], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[(B * B), $MachinePrecision] - t$95$0), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + N[(-0.5 * N[(N[(B * B), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] / (-B)), $MachinePrecision] * N[Sqrt[N[(F * N[(A - N[Sqrt[A ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := \left(4 \cdot A\right) \cdot C\\
\mathbf{if}\;B \leq 9.5 \cdot 10^{+49}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left(B \cdot B - t\_0\right) \cdot F\right)\right) \cdot \left(\left(A + -0.5 \cdot \frac{B \cdot B}{C}\right) + A\right)}}{\left(-B\right) \cdot B + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{-B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\
\end{array}
\end{array}
if B < 9.49999999999999969e49Initial program 23.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-*.f6422.3
Applied rewrites22.3%
lift-pow.f64N/A
pow2N/A
lift-*.f6422.3
lift-pow.f64N/A
pow2N/A
lift-*.f6422.3
Applied rewrites22.3%
if 9.49999999999999969e49 < B Initial program 9.5%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6455.9
Applied rewrites55.9%
Final simplification29.8%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (* (* 4.0 A) C)))
(if (<= B 5.1e+54)
(/
(sqrt
(* (* 2.0 (* (- (* B B) t_0) F)) (+ (+ A (* -0.5 (/ (* B B) C))) A)))
(+ (* (- B) B) t_0))
(- (sqrt (* (* (/ F B) (/ (- A B) B)) 2.0))))))assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (B <= 5.1e+54) {
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
NOTE: A, B, 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, 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
real(8) :: tmp
t_0 = (4.0d0 * a) * c
if (b <= 5.1d+54) then
tmp = sqrt(((2.0d0 * (((b * b) - t_0) * f)) * ((a + ((-0.5d0) * ((b * b) / c))) + a))) / ((-b * b) + t_0)
else
tmp = -sqrt((((f / b) * ((a - b) / b)) * 2.0d0))
end if
code = tmp
end function
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double t_0 = (4.0 * A) * C;
double tmp;
if (B <= 5.1e+54) {
tmp = Math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
} else {
tmp = -Math.sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): t_0 = (4.0 * A) * C tmp = 0 if B <= 5.1e+54: tmp = math.sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0) else: tmp = -math.sqrt((((F / B) * ((A - B) / B)) * 2.0)) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) t_0 = Float64(Float64(4.0 * A) * C) tmp = 0.0 if (B <= 5.1e+54) tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64(Float64(B * B) - t_0) * F)) * Float64(Float64(A + Float64(-0.5 * Float64(Float64(B * B) / C))) + A))) / Float64(Float64(Float64(-B) * B) + t_0)); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - B) / B)) * 2.0))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (4.0 * A) * C;
tmp = 0.0;
if (B <= 5.1e+54)
tmp = sqrt(((2.0 * (((B * B) - t_0) * F)) * ((A + (-0.5 * ((B * B) / C))) + A))) / ((-B * B) + t_0);
else
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, If[LessEqual[B, 5.1e+54], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[(B * B), $MachinePrecision] - t$95$0), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + N[(-0.5 * N[(N[(B * B), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[((-B) * B), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - B), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
t_0 := \left(4 \cdot A\right) \cdot C\\
\mathbf{if}\;B \leq 5.1 \cdot 10^{+54}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left(B \cdot B - t\_0\right) \cdot F\right)\right) \cdot \left(\left(A + -0.5 \cdot \frac{B \cdot B}{C}\right) + A\right)}}{\left(-B\right) \cdot B + t\_0}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - B}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if B < 5.10000000000000009e54Initial program 23.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-*.f6422.3
Applied rewrites22.3%
lift-pow.f64N/A
pow2N/A
lift-*.f6422.3
lift-pow.f64N/A
pow2N/A
lift-*.f6422.3
Applied rewrites22.3%
if 5.10000000000000009e54 < B Initial program 9.5%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites18.9%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f6418.9
Applied rewrites18.9%
Applied rewrites55.2%
Taylor expanded in A around 0
Applied rewrites50.8%
Final simplification28.7%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (if (<= B 3350.0) (- (sqrt (* (/ F C) -1.0))) (- (sqrt (* (* (/ F B) (/ (- A B) B)) 2.0)))))
assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double tmp;
if (B <= 3350.0) {
tmp = -sqrt(((F / C) * -1.0));
} else {
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
NOTE: A, B, 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, 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) :: tmp
if (b <= 3350.0d0) then
tmp = -sqrt(((f / c) * (-1.0d0)))
else
tmp = -sqrt((((f / b) * ((a - b) / b)) * 2.0d0))
end if
code = tmp
end function
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double tmp;
if (B <= 3350.0) {
tmp = -Math.sqrt(((F / C) * -1.0));
} else {
tmp = -Math.sqrt((((F / B) * ((A - B) / B)) * 2.0));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): tmp = 0 if B <= 3350.0: tmp = -math.sqrt(((F / C) * -1.0)) else: tmp = -math.sqrt((((F / B) * ((A - B) / B)) * 2.0)) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) tmp = 0.0 if (B <= 3350.0) tmp = Float64(-sqrt(Float64(Float64(F / C) * -1.0))); else tmp = Float64(-sqrt(Float64(Float64(Float64(F / B) * Float64(Float64(A - B) / B)) * 2.0))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
tmp = 0.0;
if (B <= 3350.0)
tmp = -sqrt(((F / C) * -1.0));
else
tmp = -sqrt((((F / B) * ((A - B) / B)) * 2.0));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[LessEqual[B, 3350.0], (-N[Sqrt[N[(N[(F / C), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision]), (-N[Sqrt[N[(N[(N[(F / B), $MachinePrecision] * N[(N[(A - B), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B \leq 3350:\\
\;\;\;\;-\sqrt{\frac{F}{C} \cdot -1}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\left(\frac{F}{B} \cdot \frac{A - B}{B}\right) \cdot 2}\\
\end{array}
\end{array}
if B < 3350Initial program 23.3%
Taylor expanded in A around -inf
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f640.0
Applied rewrites0.0%
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6416.1
Applied rewrites16.1%
if 3350 < B Initial program 13.0%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites19.7%
Taylor expanded in C around 0
pow2N/A
pow2N/A
lower-/.f64N/A
lift-hypot.f64N/A
lift--.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f6419.7
Applied rewrites19.7%
Applied rewrites51.1%
Taylor expanded in A around 0
Applied rewrites45.9%
Final simplification23.8%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (if (<= A -1.7e+145) (* (sqrt (* A F)) (/ -2.0 B)) (- (sqrt (* -2.0 (/ F B))))))
assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double tmp;
if (A <= -1.7e+145) {
tmp = sqrt((A * F)) * (-2.0 / B);
} else {
tmp = -sqrt((-2.0 * (F / B)));
}
return tmp;
}
NOTE: A, B, 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, 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) :: tmp
if (a <= (-1.7d+145)) then
tmp = sqrt((a * f)) * ((-2.0d0) / b)
else
tmp = -sqrt(((-2.0d0) * (f / b)))
end if
code = tmp
end function
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double tmp;
if (A <= -1.7e+145) {
tmp = Math.sqrt((A * F)) * (-2.0 / B);
} else {
tmp = -Math.sqrt((-2.0 * (F / B)));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): tmp = 0 if A <= -1.7e+145: tmp = math.sqrt((A * F)) * (-2.0 / B) else: tmp = -math.sqrt((-2.0 * (F / B))) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) tmp = 0.0 if (A <= -1.7e+145) tmp = Float64(sqrt(Float64(A * F)) * Float64(-2.0 / B)); else tmp = Float64(-sqrt(Float64(-2.0 * Float64(F / B)))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
tmp = 0.0;
if (A <= -1.7e+145)
tmp = sqrt((A * F)) * (-2.0 / B);
else
tmp = -sqrt((-2.0 * (F / B)));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[LessEqual[A, -1.7e+145], N[(N[Sqrt[N[(A * F), $MachinePrecision]], $MachinePrecision] * N[(-2.0 / B), $MachinePrecision]), $MachinePrecision], (-N[Sqrt[N[(-2.0 * N[(F / B), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;A \leq -1.7 \cdot 10^{+145}:\\
\;\;\;\;\sqrt{A \cdot F} \cdot \frac{-2}{B}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{-2 \cdot \frac{F}{B}}\\
\end{array}
\end{array}
if A < -1.7e145Initial program 4.8%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6415.3
Applied rewrites15.3%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-sqrt.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-/.f6413.2
Applied rewrites13.2%
if -1.7e145 < A Initial program 23.1%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites22.6%
Taylor expanded in B around inf
lower-*.f64N/A
lower-/.f6415.7
Applied rewrites15.7%
Final simplification15.3%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (if (<= B 2e+85) (- (sqrt (* (/ F C) -1.0))) (- (sqrt (* -2.0 (/ F B))))))
assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
double tmp;
if (B <= 2e+85) {
tmp = -sqrt(((F / C) * -1.0));
} else {
tmp = -sqrt((-2.0 * (F / B)));
}
return tmp;
}
NOTE: A, B, 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, 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) :: tmp
if (b <= 2d+85) then
tmp = -sqrt(((f / c) * (-1.0d0)))
else
tmp = -sqrt(((-2.0d0) * (f / b)))
end if
code = tmp
end function
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
double tmp;
if (B <= 2e+85) {
tmp = -Math.sqrt(((F / C) * -1.0));
} else {
tmp = -Math.sqrt((-2.0 * (F / B)));
}
return tmp;
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): tmp = 0 if B <= 2e+85: tmp = -math.sqrt(((F / C) * -1.0)) else: tmp = -math.sqrt((-2.0 * (F / B))) return tmp
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) tmp = 0.0 if (B <= 2e+85) tmp = Float64(-sqrt(Float64(Float64(F / C) * -1.0))); else tmp = Float64(-sqrt(Float64(-2.0 * Float64(F / B)))); end return tmp end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp_2 = code(A, B, C, F)
tmp = 0.0;
if (B <= 2e+85)
tmp = -sqrt(((F / C) * -1.0));
else
tmp = -sqrt((-2.0 * (F / B)));
end
tmp_2 = tmp;
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[LessEqual[B, 2e+85], (-N[Sqrt[N[(N[(F / C), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision]), (-N[Sqrt[N[(-2.0 * N[(F / B), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\begin{array}{l}
\mathbf{if}\;B \leq 2 \cdot 10^{+85}:\\
\;\;\;\;-\sqrt{\frac{F}{C} \cdot -1}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{-2 \cdot \frac{F}{B}}\\
\end{array}
\end{array}
if B < 2e85Initial program 23.9%
Taylor expanded in A around -inf
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f640.0
Applied rewrites0.0%
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6415.7
Applied rewrites15.7%
if 2e85 < B Initial program 8.2%
Taylor expanded in F around 0
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites16.3%
Taylor expanded in B around inf
lower-*.f64N/A
lower-/.f6453.9
Applied rewrites53.9%
Final simplification23.6%
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (* (sqrt (* A F)) (/ -2.0 B)))
assert(A < B && B < C && C < F);
double code(double A, double B, double C, double F) {
return sqrt((A * F)) * (-2.0 / B);
}
NOTE: A, B, 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, 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
code = sqrt((a * f)) * ((-2.0d0) / b)
end function
assert A < B && B < C && C < F;
public static double code(double A, double B, double C, double F) {
return Math.sqrt((A * F)) * (-2.0 / B);
}
[A, B, C, F] = sort([A, B, C, F]) def code(A, B, C, F): return math.sqrt((A * F)) * (-2.0 / B)
A, B, C, F = sort([A, B, C, F]) function code(A, B, C, F) return Float64(sqrt(Float64(A * F)) * Float64(-2.0 / B)) end
A, B, C, F = num2cell(sort([A, B, C, F])){:}
function tmp = code(A, B, C, F)
tmp = sqrt((A * F)) * (-2.0 / B);
end
NOTE: A, B, C, and F should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := N[(N[Sqrt[N[(A * F), $MachinePrecision]], $MachinePrecision] * N[(-2.0 / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[A, B, C, F] = \mathsf{sort}([A, B, C, F])\\
\\
\sqrt{A \cdot F} \cdot \frac{-2}{B}
\end{array}
Initial program 20.6%
Taylor expanded in C around 0
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6417.5
Applied rewrites17.5%
Taylor expanded in A around -inf
lower-*.f64N/A
lower-sqrt.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-/.f644.8
Applied rewrites4.8%
herbie shell --seed 2025084
(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))))