
(FPCore (z0 z1 z2) :precision binary64 (sqrt (- (* z0 z0) (* z1 (* z2 4)))))
double code(double z0, double z1, double z2) {
return sqrt(((z0 * z0) - (z1 * (z2 * 4.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(z0, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
code = sqrt(((z0 * z0) - (z1 * (z2 * 4.0d0))))
end function
public static double code(double z0, double z1, double z2) {
return Math.sqrt(((z0 * z0) - (z1 * (z2 * 4.0))));
}
def code(z0, z1, z2): return math.sqrt(((z0 * z0) - (z1 * (z2 * 4.0))))
function code(z0, z1, z2) return sqrt(Float64(Float64(z0 * z0) - Float64(z1 * Float64(z2 * 4.0)))) end
function tmp = code(z0, z1, z2) tmp = sqrt(((z0 * z0) - (z1 * (z2 * 4.0)))); end
code[z0_, z1_, z2_] := N[Sqrt[N[(N[(z0 * z0), $MachinePrecision] - N[(z1 * N[(z2 * 4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{z0 \cdot z0 - z1 \cdot \left(z2 \cdot 4\right)}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z0 z1 z2) :precision binary64 (sqrt (- (* z0 z0) (* z1 (* z2 4)))))
double code(double z0, double z1, double z2) {
return sqrt(((z0 * z0) - (z1 * (z2 * 4.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(z0, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
code = sqrt(((z0 * z0) - (z1 * (z2 * 4.0d0))))
end function
public static double code(double z0, double z1, double z2) {
return Math.sqrt(((z0 * z0) - (z1 * (z2 * 4.0))));
}
def code(z0, z1, z2): return math.sqrt(((z0 * z0) - (z1 * (z2 * 4.0))))
function code(z0, z1, z2) return sqrt(Float64(Float64(z0 * z0) - Float64(z1 * Float64(z2 * 4.0)))) end
function tmp = code(z0, z1, z2) tmp = sqrt(((z0 * z0) - (z1 * (z2 * 4.0)))); end
code[z0_, z1_, z2_] := N[Sqrt[N[(N[(z0 * z0), $MachinePrecision] - N[(z1 * N[(z2 * 4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{z0 \cdot z0 - z1 \cdot \left(z2 \cdot 4\right)}
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (* (fabs z0) (fabs z0)))
(t_1 (sqrt (- t_0 (* z1 (* z2 4)))))
(t_2 (- (* (* (/ z1 t_0) z2) -4) -1)))
(if (<=
t_1
3019169939857233/30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808)
(*
(sqrt (- (fabs z0) (* (/ (* 4 z2) (fabs z0)) z1)))
(sqrt (fabs z0)))
(if (<=
t_1
20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968)
t_1
(* (sqrt (sqrt t_2)) (fabs (* (pow t_2 1/4) (- (fabs z0)))))))))double code(double z0, double z1, double z2) {
double t_0 = fabs(z0) * fabs(z0);
double t_1 = sqrt((t_0 - (z1 * (z2 * 4.0))));
double t_2 = (((z1 / t_0) * z2) * -4.0) - -1.0;
double tmp;
if (t_1 <= 1e-154) {
tmp = sqrt((fabs(z0) - (((4.0 * z2) / fabs(z0)) * z1))) * sqrt(fabs(z0));
} else if (t_1 <= 2e+148) {
tmp = t_1;
} else {
tmp = sqrt(sqrt(t_2)) * fabs((pow(t_2, 0.25) * -fabs(z0)));
}
return tmp;
}
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(z0, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = abs(z0) * abs(z0)
t_1 = sqrt((t_0 - (z1 * (z2 * 4.0d0))))
t_2 = (((z1 / t_0) * z2) * (-4.0d0)) - (-1.0d0)
if (t_1 <= 1d-154) then
tmp = sqrt((abs(z0) - (((4.0d0 * z2) / abs(z0)) * z1))) * sqrt(abs(z0))
else if (t_1 <= 2d+148) then
tmp = t_1
else
tmp = sqrt(sqrt(t_2)) * abs(((t_2 ** 0.25d0) * -abs(z0)))
end if
code = tmp
end function
public static double code(double z0, double z1, double z2) {
double t_0 = Math.abs(z0) * Math.abs(z0);
double t_1 = Math.sqrt((t_0 - (z1 * (z2 * 4.0))));
double t_2 = (((z1 / t_0) * z2) * -4.0) - -1.0;
double tmp;
if (t_1 <= 1e-154) {
tmp = Math.sqrt((Math.abs(z0) - (((4.0 * z2) / Math.abs(z0)) * z1))) * Math.sqrt(Math.abs(z0));
} else if (t_1 <= 2e+148) {
tmp = t_1;
} else {
tmp = Math.sqrt(Math.sqrt(t_2)) * Math.abs((Math.pow(t_2, 0.25) * -Math.abs(z0)));
}
return tmp;
}
def code(z0, z1, z2): t_0 = math.fabs(z0) * math.fabs(z0) t_1 = math.sqrt((t_0 - (z1 * (z2 * 4.0)))) t_2 = (((z1 / t_0) * z2) * -4.0) - -1.0 tmp = 0 if t_1 <= 1e-154: tmp = math.sqrt((math.fabs(z0) - (((4.0 * z2) / math.fabs(z0)) * z1))) * math.sqrt(math.fabs(z0)) elif t_1 <= 2e+148: tmp = t_1 else: tmp = math.sqrt(math.sqrt(t_2)) * math.fabs((math.pow(t_2, 0.25) * -math.fabs(z0))) return tmp
function code(z0, z1, z2) t_0 = Float64(abs(z0) * abs(z0)) t_1 = sqrt(Float64(t_0 - Float64(z1 * Float64(z2 * 4.0)))) t_2 = Float64(Float64(Float64(Float64(z1 / t_0) * z2) * -4.0) - -1.0) tmp = 0.0 if (t_1 <= 1e-154) tmp = Float64(sqrt(Float64(abs(z0) - Float64(Float64(Float64(4.0 * z2) / abs(z0)) * z1))) * sqrt(abs(z0))); elseif (t_1 <= 2e+148) tmp = t_1; else tmp = Float64(sqrt(sqrt(t_2)) * abs(Float64((t_2 ^ 0.25) * Float64(-abs(z0))))); end return tmp end
function tmp_2 = code(z0, z1, z2) t_0 = abs(z0) * abs(z0); t_1 = sqrt((t_0 - (z1 * (z2 * 4.0)))); t_2 = (((z1 / t_0) * z2) * -4.0) - -1.0; tmp = 0.0; if (t_1 <= 1e-154) tmp = sqrt((abs(z0) - (((4.0 * z2) / abs(z0)) * z1))) * sqrt(abs(z0)); elseif (t_1 <= 2e+148) tmp = t_1; else tmp = sqrt(sqrt(t_2)) * abs(((t_2 ^ 0.25) * -abs(z0))); end tmp_2 = tmp; end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(t$95$0 - N[(z1 * N[(z2 * 4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(z1 / t$95$0), $MachinePrecision] * z2), $MachinePrecision] * -4), $MachinePrecision] - -1), $MachinePrecision]}, If[LessEqual[t$95$1, 3019169939857233/30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808], N[(N[Sqrt[N[(N[Abs[z0], $MachinePrecision] - N[(N[(N[(4 * z2), $MachinePrecision] / N[Abs[z0], $MachinePrecision]), $MachinePrecision] * z1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[z0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968], t$95$1, N[(N[Sqrt[N[Sqrt[t$95$2], $MachinePrecision]], $MachinePrecision] * N[Abs[N[(N[Power[t$95$2, 1/4], $MachinePrecision] * (-N[Abs[z0], $MachinePrecision])), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \left|z0\right| \cdot \left|z0\right|\\
t_1 := \sqrt{t\_0 - z1 \cdot \left(z2 \cdot 4\right)}\\
t_2 := \left(\frac{z1}{t\_0} \cdot z2\right) \cdot -4 - -1\\
\mathbf{if}\;t\_1 \leq \frac{3019169939857233}{30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808}:\\
\;\;\;\;\sqrt{\left|z0\right| - \frac{4 \cdot z2}{\left|z0\right|} \cdot z1} \cdot \sqrt{\left|z0\right|}\\
\mathbf{elif}\;t\_1 \leq 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\sqrt{t\_2}} \cdot \left|{t\_2}^{\frac{1}{4}} \cdot \left(-\left|z0\right|\right)\right|\\
\end{array}
if (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 z1 (*.f64 z2 #s(literal 4 binary64))))) < 9.9999999999999997e-155Initial program 60.6%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
pow1/2N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
sqrt-pow2N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites60.2%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites43.9%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites45.6%
Applied rewrites43.4%
if 9.9999999999999997e-155 < (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 z1 (*.f64 z2 #s(literal 4 binary64))))) < 2.0000000000000001e148Initial program 60.6%
if 2.0000000000000001e148 < (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 z1 (*.f64 z2 #s(literal 4 binary64))))) Initial program 60.6%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
pow1/2N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
sqrt-pow2N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites60.2%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites43.9%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites45.6%
Applied rewrites76.3%
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (* (fabs z0) (fabs z0)))
(t_1 (sqrt (- t_0 (* z1 (* z2 4))))))
(if (<=
t_1
3019169939857233/30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808)
(*
(sqrt (- (fabs z0) (* (/ (* 4 z2) (fabs z0)) z1)))
(sqrt (fabs z0)))
(if (<=
t_1
20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968)
t_1
(fabs (* (sqrt (- (* (* (/ z1 t_0) z2) -4) -1)) (fabs z0)))))))double code(double z0, double z1, double z2) {
double t_0 = fabs(z0) * fabs(z0);
double t_1 = sqrt((t_0 - (z1 * (z2 * 4.0))));
double tmp;
if (t_1 <= 1e-154) {
tmp = sqrt((fabs(z0) - (((4.0 * z2) / fabs(z0)) * z1))) * sqrt(fabs(z0));
} else if (t_1 <= 2e+148) {
tmp = t_1;
} else {
tmp = fabs((sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * fabs(z0)));
}
return tmp;
}
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(z0, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = abs(z0) * abs(z0)
t_1 = sqrt((t_0 - (z1 * (z2 * 4.0d0))))
if (t_1 <= 1d-154) then
tmp = sqrt((abs(z0) - (((4.0d0 * z2) / abs(z0)) * z1))) * sqrt(abs(z0))
else if (t_1 <= 2d+148) then
tmp = t_1
else
tmp = abs((sqrt(((((z1 / t_0) * z2) * (-4.0d0)) - (-1.0d0))) * abs(z0)))
end if
code = tmp
end function
public static double code(double z0, double z1, double z2) {
double t_0 = Math.abs(z0) * Math.abs(z0);
double t_1 = Math.sqrt((t_0 - (z1 * (z2 * 4.0))));
double tmp;
if (t_1 <= 1e-154) {
tmp = Math.sqrt((Math.abs(z0) - (((4.0 * z2) / Math.abs(z0)) * z1))) * Math.sqrt(Math.abs(z0));
} else if (t_1 <= 2e+148) {
tmp = t_1;
} else {
tmp = Math.abs((Math.sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * Math.abs(z0)));
}
return tmp;
}
def code(z0, z1, z2): t_0 = math.fabs(z0) * math.fabs(z0) t_1 = math.sqrt((t_0 - (z1 * (z2 * 4.0)))) tmp = 0 if t_1 <= 1e-154: tmp = math.sqrt((math.fabs(z0) - (((4.0 * z2) / math.fabs(z0)) * z1))) * math.sqrt(math.fabs(z0)) elif t_1 <= 2e+148: tmp = t_1 else: tmp = math.fabs((math.sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * math.fabs(z0))) return tmp
function code(z0, z1, z2) t_0 = Float64(abs(z0) * abs(z0)) t_1 = sqrt(Float64(t_0 - Float64(z1 * Float64(z2 * 4.0)))) tmp = 0.0 if (t_1 <= 1e-154) tmp = Float64(sqrt(Float64(abs(z0) - Float64(Float64(Float64(4.0 * z2) / abs(z0)) * z1))) * sqrt(abs(z0))); elseif (t_1 <= 2e+148) tmp = t_1; else tmp = abs(Float64(sqrt(Float64(Float64(Float64(Float64(z1 / t_0) * z2) * -4.0) - -1.0)) * abs(z0))); end return tmp end
function tmp_2 = code(z0, z1, z2) t_0 = abs(z0) * abs(z0); t_1 = sqrt((t_0 - (z1 * (z2 * 4.0)))); tmp = 0.0; if (t_1 <= 1e-154) tmp = sqrt((abs(z0) - (((4.0 * z2) / abs(z0)) * z1))) * sqrt(abs(z0)); elseif (t_1 <= 2e+148) tmp = t_1; else tmp = abs((sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * abs(z0))); end tmp_2 = tmp; end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(t$95$0 - N[(z1 * N[(z2 * 4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, 3019169939857233/30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808], N[(N[Sqrt[N[(N[Abs[z0], $MachinePrecision] - N[(N[(N[(4 * z2), $MachinePrecision] / N[Abs[z0], $MachinePrecision]), $MachinePrecision] * z1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[z0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968], t$95$1, N[Abs[N[(N[Sqrt[N[(N[(N[(N[(z1 / t$95$0), $MachinePrecision] * z2), $MachinePrecision] * -4), $MachinePrecision] - -1), $MachinePrecision]], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \left|z0\right| \cdot \left|z0\right|\\
t_1 := \sqrt{t\_0 - z1 \cdot \left(z2 \cdot 4\right)}\\
\mathbf{if}\;t\_1 \leq \frac{3019169939857233}{30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808}:\\
\;\;\;\;\sqrt{\left|z0\right| - \frac{4 \cdot z2}{\left|z0\right|} \cdot z1} \cdot \sqrt{\left|z0\right|}\\
\mathbf{elif}\;t\_1 \leq 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left|\sqrt{\left(\frac{z1}{t\_0} \cdot z2\right) \cdot -4 - -1} \cdot \left|z0\right|\right|\\
\end{array}
if (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 z1 (*.f64 z2 #s(literal 4 binary64))))) < 9.9999999999999997e-155Initial program 60.6%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
pow1/2N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
sqrt-pow2N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites60.2%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites43.9%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites45.6%
Applied rewrites43.4%
if 9.9999999999999997e-155 < (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 z1 (*.f64 z2 #s(literal 4 binary64))))) < 2.0000000000000001e148Initial program 60.6%
if 2.0000000000000001e148 < (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 z1 (*.f64 z2 #s(literal 4 binary64))))) Initial program 60.6%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
pow1/2N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
sqrt-pow2N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites60.2%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites43.9%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites45.6%
Applied rewrites76.4%
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (* (fabs z0) (fabs z0))))
(if (<= (fabs z0) 68000000000000000000)
(sqrt (- t_0 (* z1 (* z2 4))))
(fabs (* (sqrt (- (* (* (/ z1 t_0) z2) -4) -1)) (fabs z0))))))double code(double z0, double z1, double z2) {
double t_0 = fabs(z0) * fabs(z0);
double tmp;
if (fabs(z0) <= 6.8e+19) {
tmp = sqrt((t_0 - (z1 * (z2 * 4.0))));
} else {
tmp = fabs((sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * fabs(z0)));
}
return tmp;
}
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(z0, z1, z2)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
real(8), intent (in) :: z2
real(8) :: t_0
real(8) :: tmp
t_0 = abs(z0) * abs(z0)
if (abs(z0) <= 6.8d+19) then
tmp = sqrt((t_0 - (z1 * (z2 * 4.0d0))))
else
tmp = abs((sqrt(((((z1 / t_0) * z2) * (-4.0d0)) - (-1.0d0))) * abs(z0)))
end if
code = tmp
end function
public static double code(double z0, double z1, double z2) {
double t_0 = Math.abs(z0) * Math.abs(z0);
double tmp;
if (Math.abs(z0) <= 6.8e+19) {
tmp = Math.sqrt((t_0 - (z1 * (z2 * 4.0))));
} else {
tmp = Math.abs((Math.sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * Math.abs(z0)));
}
return tmp;
}
def code(z0, z1, z2): t_0 = math.fabs(z0) * math.fabs(z0) tmp = 0 if math.fabs(z0) <= 6.8e+19: tmp = math.sqrt((t_0 - (z1 * (z2 * 4.0)))) else: tmp = math.fabs((math.sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * math.fabs(z0))) return tmp
function code(z0, z1, z2) t_0 = Float64(abs(z0) * abs(z0)) tmp = 0.0 if (abs(z0) <= 6.8e+19) tmp = sqrt(Float64(t_0 - Float64(z1 * Float64(z2 * 4.0)))); else tmp = abs(Float64(sqrt(Float64(Float64(Float64(Float64(z1 / t_0) * z2) * -4.0) - -1.0)) * abs(z0))); end return tmp end
function tmp_2 = code(z0, z1, z2) t_0 = abs(z0) * abs(z0); tmp = 0.0; if (abs(z0) <= 6.8e+19) tmp = sqrt((t_0 - (z1 * (z2 * 4.0)))); else tmp = abs((sqrt(((((z1 / t_0) * z2) * -4.0) - -1.0)) * abs(z0))); end tmp_2 = tmp; end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[z0], $MachinePrecision], 68000000000000000000], N[Sqrt[N[(t$95$0 - N[(z1 * N[(z2 * 4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[Sqrt[N[(N[(N[(N[(z1 / t$95$0), $MachinePrecision] * z2), $MachinePrecision] * -4), $MachinePrecision] - -1), $MachinePrecision]], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|z0\right| \cdot \left|z0\right|\\
\mathbf{if}\;\left|z0\right| \leq 68000000000000000000:\\
\;\;\;\;\sqrt{t\_0 - z1 \cdot \left(z2 \cdot 4\right)}\\
\mathbf{else}:\\
\;\;\;\;\left|\sqrt{\left(\frac{z1}{t\_0} \cdot z2\right) \cdot -4 - -1} \cdot \left|z0\right|\right|\\
\end{array}
if z0 < 6.8e19Initial program 60.6%
if 6.8e19 < z0 Initial program 60.6%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
pow1/2N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
sqrt-pow2N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites60.2%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites43.9%
lift-pow.f64N/A
lift--.f64N/A
sub-to-mult-revN/A
lift-/.f64N/A
lift--.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites45.6%
Applied rewrites76.4%
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1 z2)
:name "(sqrt (- (* z0 z0) (* z1 (* z2 4))))"
:precision binary64
(sqrt (- (* z0 z0) (* z1 (* z2 4)))))