
(FPCore (z0 z1 z2) :precision binary64 (pow (+ (* z0 z0) (* z1 z1)) (* 1/2 z2)))
double code(double z0, double z1, double z2) {
return pow(((z0 * z0) + (z1 * z1)), (0.5 * z2));
}
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 = ((z0 * z0) + (z1 * z1)) ** (0.5d0 * z2)
end function
public static double code(double z0, double z1, double z2) {
return Math.pow(((z0 * z0) + (z1 * z1)), (0.5 * z2));
}
def code(z0, z1, z2): return math.pow(((z0 * z0) + (z1 * z1)), (0.5 * z2))
function code(z0, z1, z2) return Float64(Float64(z0 * z0) + Float64(z1 * z1)) ^ Float64(0.5 * z2) end
function tmp = code(z0, z1, z2) tmp = ((z0 * z0) + (z1 * z1)) ^ (0.5 * z2); end
code[z0_, z1_, z2_] := N[Power[N[(N[(z0 * z0), $MachinePrecision] + N[(z1 * z1), $MachinePrecision]), $MachinePrecision], N[(1/2 * z2), $MachinePrecision]], $MachinePrecision]
{\left(z0 \cdot z0 + z1 \cdot z1\right)}^{\left(\frac{1}{2} \cdot z2\right)}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z0 z1 z2) :precision binary64 (pow (+ (* z0 z0) (* z1 z1)) (* 1/2 z2)))
double code(double z0, double z1, double z2) {
return pow(((z0 * z0) + (z1 * z1)), (0.5 * z2));
}
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 = ((z0 * z0) + (z1 * z1)) ** (0.5d0 * z2)
end function
public static double code(double z0, double z1, double z2) {
return Math.pow(((z0 * z0) + (z1 * z1)), (0.5 * z2));
}
def code(z0, z1, z2): return math.pow(((z0 * z0) + (z1 * z1)), (0.5 * z2))
function code(z0, z1, z2) return Float64(Float64(z0 * z0) + Float64(z1 * z1)) ^ Float64(0.5 * z2) end
function tmp = code(z0, z1, z2) tmp = ((z0 * z0) + (z1 * z1)) ^ (0.5 * z2); end
code[z0_, z1_, z2_] := N[Power[N[(N[(z0 * z0), $MachinePrecision] + N[(z1 * z1), $MachinePrecision]), $MachinePrecision], N[(1/2 * z2), $MachinePrecision]], $MachinePrecision]
{\left(z0 \cdot z0 + z1 \cdot z1\right)}^{\left(\frac{1}{2} \cdot z2\right)}
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (fabs (fabs z0))) (t_1 (* (fabs z0) (fabs z0))))
(if (<= (fabs z0) 6338253001141147/79228162514264337593543950336)
(pow (+ t_1 (* z1 z1)) (* 1/2 z2))
(*
(pow (+ (* (* (pow (* t_1 t_1) -1/4) z1) z1) t_0) (* z2 1/2))
(pow t_0 (* z2 1/2))))))double code(double z0, double z1, double z2) {
double t_0 = fabs(fabs(z0));
double t_1 = fabs(z0) * fabs(z0);
double tmp;
if (fabs(z0) <= 8e-14) {
tmp = pow((t_1 + (z1 * z1)), (0.5 * z2));
} else {
tmp = pow((((pow((t_1 * t_1), -0.25) * z1) * z1) + t_0), (z2 * 0.5)) * pow(t_0, (z2 * 0.5));
}
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(abs(z0))
t_1 = abs(z0) * abs(z0)
if (abs(z0) <= 8d-14) then
tmp = (t_1 + (z1 * z1)) ** (0.5d0 * z2)
else
tmp = ((((((t_1 * t_1) ** (-0.25d0)) * z1) * z1) + t_0) ** (z2 * 0.5d0)) * (t_0 ** (z2 * 0.5d0))
end if
code = tmp
end function
public static double code(double z0, double z1, double z2) {
double t_0 = Math.abs(Math.abs(z0));
double t_1 = Math.abs(z0) * Math.abs(z0);
double tmp;
if (Math.abs(z0) <= 8e-14) {
tmp = Math.pow((t_1 + (z1 * z1)), (0.5 * z2));
} else {
tmp = Math.pow((((Math.pow((t_1 * t_1), -0.25) * z1) * z1) + t_0), (z2 * 0.5)) * Math.pow(t_0, (z2 * 0.5));
}
return tmp;
}
def code(z0, z1, z2): t_0 = math.fabs(math.fabs(z0)) t_1 = math.fabs(z0) * math.fabs(z0) tmp = 0 if math.fabs(z0) <= 8e-14: tmp = math.pow((t_1 + (z1 * z1)), (0.5 * z2)) else: tmp = math.pow((((math.pow((t_1 * t_1), -0.25) * z1) * z1) + t_0), (z2 * 0.5)) * math.pow(t_0, (z2 * 0.5)) return tmp
function code(z0, z1, z2) t_0 = abs(abs(z0)) t_1 = Float64(abs(z0) * abs(z0)) tmp = 0.0 if (abs(z0) <= 8e-14) tmp = Float64(t_1 + Float64(z1 * z1)) ^ Float64(0.5 * z2); else tmp = Float64((Float64(Float64(Float64((Float64(t_1 * t_1) ^ -0.25) * z1) * z1) + t_0) ^ Float64(z2 * 0.5)) * (t_0 ^ Float64(z2 * 0.5))); end return tmp end
function tmp_2 = code(z0, z1, z2) t_0 = abs(abs(z0)); t_1 = abs(z0) * abs(z0); tmp = 0.0; if (abs(z0) <= 8e-14) tmp = (t_1 + (z1 * z1)) ^ (0.5 * z2); else tmp = ((((((t_1 * t_1) ^ -0.25) * z1) * z1) + t_0) ^ (z2 * 0.5)) * (t_0 ^ (z2 * 0.5)); end tmp_2 = tmp; end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[Abs[N[Abs[z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[z0], $MachinePrecision], 6338253001141147/79228162514264337593543950336], N[Power[N[(t$95$1 + N[(z1 * z1), $MachinePrecision]), $MachinePrecision], N[(1/2 * z2), $MachinePrecision]], $MachinePrecision], N[(N[Power[N[(N[(N[(N[Power[N[(t$95$1 * t$95$1), $MachinePrecision], -1/4], $MachinePrecision] * z1), $MachinePrecision] * z1), $MachinePrecision] + t$95$0), $MachinePrecision], N[(z2 * 1/2), $MachinePrecision]], $MachinePrecision] * N[Power[t$95$0, N[(z2 * 1/2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\left|z0\right|\right|\\
t_1 := \left|z0\right| \cdot \left|z0\right|\\
\mathbf{if}\;\left|z0\right| \leq \frac{6338253001141147}{79228162514264337593543950336}:\\
\;\;\;\;{\left(t\_1 + z1 \cdot z1\right)}^{\left(\frac{1}{2} \cdot z2\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(\left({\left(t\_1 \cdot t\_1\right)}^{\frac{-1}{4}} \cdot z1\right) \cdot z1 + t\_0\right)}^{\left(z2 \cdot \frac{1}{2}\right)} \cdot {t\_0}^{\left(z2 \cdot \frac{1}{2}\right)}\\
\end{array}
if z0 < 8e-14Initial program 76.3%
if 8e-14 < z0 Initial program 76.3%
unpow1N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-to-fractionN/A
pow-subN/A
lower-unsound-pow.f32N/A
lower-pow.f32N/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-unsound-/.f64N/A
lower-fabs.f64N/A
lower-unsound-pow.f64N/A
metadata-evalN/A
metadata-eval76.3%
Applied rewrites76.3%
lift-pow.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
add-to-fractionN/A
mult-flipN/A
lift-pow.f64N/A
pow-flipN/A
metadata-evalN/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-fabs.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites56.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
remove-double-negN/A
distribute-rgt-neg-outN/A
lower-*.f64N/A
distribute-rgt-neg-outN/A
remove-double-negN/A
lower-*.f6463.3%
lift-pow.f64N/A
metadata-evalN/A
pow-negN/A
lower-unsound-pow.f32N/A
lower-pow.f32N/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-fabs.f64N/A
lower-unsound-/.f6472.5%
Applied rewrites72.5%
lift-/.f64N/A
inv-powN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-pow2N/A
fabs-sqrN/A
rem-sqrt-square-revN/A
sqrt-pow2N/A
lower-*.f32N/A
lower-unsound-*.f32N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
lower-unsound-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval56.9%
Applied rewrites56.9%
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (fabs (fabs z0))) (t_1 (* (fabs z0) (fabs z0))))
(if (<= (fabs z0) 6338253001141147/79228162514264337593543950336)
(pow (+ t_1 (* z1 z1)) (* 1/2 z2))
(*
(pow (+ (* (* (sqrt (/ 1 t_1)) z1) z1) t_0) (* z2 1/2))
(pow t_0 (* z2 1/2))))))double code(double z0, double z1, double z2) {
double t_0 = fabs(fabs(z0));
double t_1 = fabs(z0) * fabs(z0);
double tmp;
if (fabs(z0) <= 8e-14) {
tmp = pow((t_1 + (z1 * z1)), (0.5 * z2));
} else {
tmp = pow((((sqrt((1.0 / t_1)) * z1) * z1) + t_0), (z2 * 0.5)) * pow(t_0, (z2 * 0.5));
}
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(abs(z0))
t_1 = abs(z0) * abs(z0)
if (abs(z0) <= 8d-14) then
tmp = (t_1 + (z1 * z1)) ** (0.5d0 * z2)
else
tmp = ((((sqrt((1.0d0 / t_1)) * z1) * z1) + t_0) ** (z2 * 0.5d0)) * (t_0 ** (z2 * 0.5d0))
end if
code = tmp
end function
public static double code(double z0, double z1, double z2) {
double t_0 = Math.abs(Math.abs(z0));
double t_1 = Math.abs(z0) * Math.abs(z0);
double tmp;
if (Math.abs(z0) <= 8e-14) {
tmp = Math.pow((t_1 + (z1 * z1)), (0.5 * z2));
} else {
tmp = Math.pow((((Math.sqrt((1.0 / t_1)) * z1) * z1) + t_0), (z2 * 0.5)) * Math.pow(t_0, (z2 * 0.5));
}
return tmp;
}
def code(z0, z1, z2): t_0 = math.fabs(math.fabs(z0)) t_1 = math.fabs(z0) * math.fabs(z0) tmp = 0 if math.fabs(z0) <= 8e-14: tmp = math.pow((t_1 + (z1 * z1)), (0.5 * z2)) else: tmp = math.pow((((math.sqrt((1.0 / t_1)) * z1) * z1) + t_0), (z2 * 0.5)) * math.pow(t_0, (z2 * 0.5)) return tmp
function code(z0, z1, z2) t_0 = abs(abs(z0)) t_1 = Float64(abs(z0) * abs(z0)) tmp = 0.0 if (abs(z0) <= 8e-14) tmp = Float64(t_1 + Float64(z1 * z1)) ^ Float64(0.5 * z2); else tmp = Float64((Float64(Float64(Float64(sqrt(Float64(1.0 / t_1)) * z1) * z1) + t_0) ^ Float64(z2 * 0.5)) * (t_0 ^ Float64(z2 * 0.5))); end return tmp end
function tmp_2 = code(z0, z1, z2) t_0 = abs(abs(z0)); t_1 = abs(z0) * abs(z0); tmp = 0.0; if (abs(z0) <= 8e-14) tmp = (t_1 + (z1 * z1)) ^ (0.5 * z2); else tmp = ((((sqrt((1.0 / t_1)) * z1) * z1) + t_0) ^ (z2 * 0.5)) * (t_0 ^ (z2 * 0.5)); end tmp_2 = tmp; end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[Abs[N[Abs[z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[z0], $MachinePrecision], 6338253001141147/79228162514264337593543950336], N[Power[N[(t$95$1 + N[(z1 * z1), $MachinePrecision]), $MachinePrecision], N[(1/2 * z2), $MachinePrecision]], $MachinePrecision], N[(N[Power[N[(N[(N[(N[Sqrt[N[(1 / t$95$1), $MachinePrecision]], $MachinePrecision] * z1), $MachinePrecision] * z1), $MachinePrecision] + t$95$0), $MachinePrecision], N[(z2 * 1/2), $MachinePrecision]], $MachinePrecision] * N[Power[t$95$0, N[(z2 * 1/2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\left|z0\right|\right|\\
t_1 := \left|z0\right| \cdot \left|z0\right|\\
\mathbf{if}\;\left|z0\right| \leq \frac{6338253001141147}{79228162514264337593543950336}:\\
\;\;\;\;{\left(t\_1 + z1 \cdot z1\right)}^{\left(\frac{1}{2} \cdot z2\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\sqrt{\frac{1}{t\_1}} \cdot z1\right) \cdot z1 + t\_0\right)}^{\left(z2 \cdot \frac{1}{2}\right)} \cdot {t\_0}^{\left(z2 \cdot \frac{1}{2}\right)}\\
\end{array}
if z0 < 8e-14Initial program 76.3%
if 8e-14 < z0 Initial program 76.3%
unpow1N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-to-fractionN/A
pow-subN/A
lower-unsound-pow.f32N/A
lower-pow.f32N/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-unsound-/.f64N/A
lower-fabs.f64N/A
lower-unsound-pow.f64N/A
metadata-evalN/A
metadata-eval76.3%
Applied rewrites76.3%
lift-pow.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
add-to-fractionN/A
mult-flipN/A
lift-pow.f64N/A
pow-flipN/A
metadata-evalN/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-fabs.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites56.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
remove-double-negN/A
distribute-rgt-neg-outN/A
lower-*.f64N/A
distribute-rgt-neg-outN/A
remove-double-negN/A
lower-*.f6463.3%
lift-pow.f64N/A
metadata-evalN/A
pow-negN/A
lower-unsound-pow.f32N/A
lower-pow.f32N/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-fabs.f64N/A
lower-unsound-/.f6472.5%
Applied rewrites72.5%
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
remove-double-negN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-undivN/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6462.6%
Applied rewrites62.6%
(FPCore (z0 z1 z2)
:precision binary64
(let* ((t_0 (fabs (fabs z0))))
(if (<= (fabs z0) 6338253001141147/79228162514264337593543950336)
(pow (+ (* (fabs z0) (fabs z0)) (* z1 z1)) (* 1/2 z2))
(*
(pow (+ (* (/ z1 t_0) z1) t_0) (* z2 1/2))
(pow t_0 (* z2 1/2))))))double code(double z0, double z1, double z2) {
double t_0 = fabs(fabs(z0));
double tmp;
if (fabs(z0) <= 8e-14) {
tmp = pow(((fabs(z0) * fabs(z0)) + (z1 * z1)), (0.5 * z2));
} else {
tmp = pow((((z1 / t_0) * z1) + t_0), (z2 * 0.5)) * pow(t_0, (z2 * 0.5));
}
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(abs(z0))
if (abs(z0) <= 8d-14) then
tmp = ((abs(z0) * abs(z0)) + (z1 * z1)) ** (0.5d0 * z2)
else
tmp = ((((z1 / t_0) * z1) + t_0) ** (z2 * 0.5d0)) * (t_0 ** (z2 * 0.5d0))
end if
code = tmp
end function
public static double code(double z0, double z1, double z2) {
double t_0 = Math.abs(Math.abs(z0));
double tmp;
if (Math.abs(z0) <= 8e-14) {
tmp = Math.pow(((Math.abs(z0) * Math.abs(z0)) + (z1 * z1)), (0.5 * z2));
} else {
tmp = Math.pow((((z1 / t_0) * z1) + t_0), (z2 * 0.5)) * Math.pow(t_0, (z2 * 0.5));
}
return tmp;
}
def code(z0, z1, z2): t_0 = math.fabs(math.fabs(z0)) tmp = 0 if math.fabs(z0) <= 8e-14: tmp = math.pow(((math.fabs(z0) * math.fabs(z0)) + (z1 * z1)), (0.5 * z2)) else: tmp = math.pow((((z1 / t_0) * z1) + t_0), (z2 * 0.5)) * math.pow(t_0, (z2 * 0.5)) return tmp
function code(z0, z1, z2) t_0 = abs(abs(z0)) tmp = 0.0 if (abs(z0) <= 8e-14) tmp = Float64(Float64(abs(z0) * abs(z0)) + Float64(z1 * z1)) ^ Float64(0.5 * z2); else tmp = Float64((Float64(Float64(Float64(z1 / t_0) * z1) + t_0) ^ Float64(z2 * 0.5)) * (t_0 ^ Float64(z2 * 0.5))); end return tmp end
function tmp_2 = code(z0, z1, z2) t_0 = abs(abs(z0)); tmp = 0.0; if (abs(z0) <= 8e-14) tmp = ((abs(z0) * abs(z0)) + (z1 * z1)) ^ (0.5 * z2); else tmp = ((((z1 / t_0) * z1) + t_0) ^ (z2 * 0.5)) * (t_0 ^ (z2 * 0.5)); end tmp_2 = tmp; end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[Abs[N[Abs[z0], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[z0], $MachinePrecision], 6338253001141147/79228162514264337593543950336], N[Power[N[(N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision] + N[(z1 * z1), $MachinePrecision]), $MachinePrecision], N[(1/2 * z2), $MachinePrecision]], $MachinePrecision], N[(N[Power[N[(N[(N[(z1 / t$95$0), $MachinePrecision] * z1), $MachinePrecision] + t$95$0), $MachinePrecision], N[(z2 * 1/2), $MachinePrecision]], $MachinePrecision] * N[Power[t$95$0, N[(z2 * 1/2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|\left|z0\right|\right|\\
\mathbf{if}\;\left|z0\right| \leq \frac{6338253001141147}{79228162514264337593543950336}:\\
\;\;\;\;{\left(\left|z0\right| \cdot \left|z0\right| + z1 \cdot z1\right)}^{\left(\frac{1}{2} \cdot z2\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{z1}{t\_0} \cdot z1 + t\_0\right)}^{\left(z2 \cdot \frac{1}{2}\right)} \cdot {t\_0}^{\left(z2 \cdot \frac{1}{2}\right)}\\
\end{array}
if z0 < 8e-14Initial program 76.3%
if 8e-14 < z0 Initial program 76.3%
unpow1N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-to-fractionN/A
pow-subN/A
lower-unsound-pow.f32N/A
lower-pow.f32N/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-unsound-/.f64N/A
lower-fabs.f64N/A
lower-unsound-pow.f64N/A
metadata-evalN/A
metadata-eval76.3%
Applied rewrites76.3%
lift-pow.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
add-to-fractionN/A
mult-flipN/A
lift-pow.f64N/A
pow-flipN/A
metadata-evalN/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-fabs.f64N/A
unpow-prod-downN/A
lower-unsound-*.f64N/A
Applied rewrites56.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
remove-double-negN/A
distribute-rgt-neg-outN/A
lower-*.f64N/A
distribute-rgt-neg-outN/A
remove-double-negN/A
lower-*.f6463.3%
lift-pow.f64N/A
metadata-evalN/A
pow-negN/A
lower-unsound-pow.f32N/A
lower-pow.f32N/A
pow1/2N/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-fabs.f64N/A
lower-unsound-/.f6472.5%
Applied rewrites72.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lower-/.f6472.5%
Applied rewrites72.5%
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1 z2)
:name "(pow (+ (* z0 z0) (* z1 z1)) (* 1/2 z2))"
:precision binary64
(pow (+ (* z0 z0) (* z1 z1)) (* 1/2 z2)))