
(FPCore (x y) :precision binary64 (- (pow x 4.0) (pow y 4.0)))
double code(double x, double y) {
return pow(x, 4.0) - pow(y, 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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x ** 4.0d0) - (y ** 4.0d0)
end function
public static double code(double x, double y) {
return Math.pow(x, 4.0) - Math.pow(y, 4.0);
}
def code(x, y): return math.pow(x, 4.0) - math.pow(y, 4.0)
function code(x, y) return Float64((x ^ 4.0) - (y ^ 4.0)) end
function tmp = code(x, y) tmp = (x ^ 4.0) - (y ^ 4.0); end
code[x_, y_] := N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]
{x}^{4} - {y}^{4}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (pow x 4.0) (pow y 4.0)))
double code(double x, double y) {
return pow(x, 4.0) - pow(y, 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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x ** 4.0d0) - (y ** 4.0d0)
end function
public static double code(double x, double y) {
return Math.pow(x, 4.0) - Math.pow(y, 4.0);
}
def code(x, y): return math.pow(x, 4.0) - math.pow(y, 4.0)
function code(x, y) return Float64((x ^ 4.0) - (y ^ 4.0)) end
function tmp = code(x, y) tmp = (x ^ 4.0) - (y ^ 4.0); end
code[x_, y_] := N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]
{x}^{4} - {y}^{4}
(FPCore (x y) :precision binary64 (let* ((t_0 (- (pow x 4.0) (pow y 4.0)))) (if (<= t_0 INFINITY) t_0 (- (pow y 4.0)))))
double code(double x, double y) {
double t_0 = pow(x, 4.0) - pow(y, 4.0);
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = -pow(y, 4.0);
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = Math.pow(x, 4.0) - Math.pow(y, 4.0);
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = -Math.pow(y, 4.0);
}
return tmp;
}
def code(x, y): t_0 = math.pow(x, 4.0) - math.pow(y, 4.0) tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = -math.pow(y, 4.0) return tmp
function code(x, y) t_0 = Float64((x ^ 4.0) - (y ^ 4.0)) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(-(y ^ 4.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x ^ 4.0) - (y ^ 4.0); tmp = 0.0; if (t_0 <= Inf) tmp = t_0; else tmp = -(y ^ 4.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, (-N[Power[y, 4.0], $MachinePrecision])]]
\begin{array}{l}
t_0 := {x}^{4} - {y}^{4}\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-{y}^{4}\\
\end{array}
if (-.f64 (pow.f64 x #s(literal 4 binary64)) (pow.f64 y #s(literal 4 binary64))) < +inf.0Initial program 85.4%
if +inf.0 < (-.f64 (pow.f64 x #s(literal 4 binary64)) (pow.f64 y #s(literal 4 binary64))) Initial program 85.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-pow.f6458.3%
Applied rewrites58.3%
remove-double-negN/A
lower-neg.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identity58.3%
Applied rewrites58.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (pow x 4.0) (pow y 4.0))) (t_1 (- (pow y 4.0)))) (if (<= t_0 -1e-316) t_1 (if (<= t_0 INFINITY) (pow x 4.0) t_1))))
double code(double x, double y) {
double t_0 = pow(x, 4.0) - pow(y, 4.0);
double t_1 = -pow(y, 4.0);
double tmp;
if (t_0 <= -1e-316) {
tmp = t_1;
} else if (t_0 <= ((double) INFINITY)) {
tmp = pow(x, 4.0);
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = Math.pow(x, 4.0) - Math.pow(y, 4.0);
double t_1 = -Math.pow(y, 4.0);
double tmp;
if (t_0 <= -1e-316) {
tmp = t_1;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = Math.pow(x, 4.0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = math.pow(x, 4.0) - math.pow(y, 4.0) t_1 = -math.pow(y, 4.0) tmp = 0 if t_0 <= -1e-316: tmp = t_1 elif t_0 <= math.inf: tmp = math.pow(x, 4.0) else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64((x ^ 4.0) - (y ^ 4.0)) t_1 = Float64(-(y ^ 4.0)) tmp = 0.0 if (t_0 <= -1e-316) tmp = t_1; elseif (t_0 <= Inf) tmp = x ^ 4.0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (x ^ 4.0) - (y ^ 4.0); t_1 = -(y ^ 4.0); tmp = 0.0; if (t_0 <= -1e-316) tmp = t_1; elseif (t_0 <= Inf) tmp = x ^ 4.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[Power[y, 4.0], $MachinePrecision])}, If[LessEqual[t$95$0, -1e-316], t$95$1, If[LessEqual[t$95$0, Infinity], N[Power[x, 4.0], $MachinePrecision], t$95$1]]]]
\begin{array}{l}
t_0 := {x}^{4} - {y}^{4}\\
t_1 := -{y}^{4}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-316}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;{x}^{4}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (-.f64 (pow.f64 x #s(literal 4 binary64)) (pow.f64 y #s(literal 4 binary64))) < -9.9999998365971443e-317 or +inf.0 < (-.f64 (pow.f64 x #s(literal 4 binary64)) (pow.f64 y #s(literal 4 binary64))) Initial program 85.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-pow.f6458.3%
Applied rewrites58.3%
remove-double-negN/A
lower-neg.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identity58.3%
Applied rewrites58.3%
if -9.9999998365971443e-317 < (-.f64 (pow.f64 x #s(literal 4 binary64)) (pow.f64 y #s(literal 4 binary64))) < +inf.0Initial program 85.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-pow.f6458.3%
Applied rewrites58.3%
Taylor expanded in x around inf
lower-pow.f6456.8%
Applied rewrites56.8%
(FPCore (x y) :precision binary64 (pow x 4.0))
double code(double x, double y) {
return pow(x, 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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x ** 4.0d0
end function
public static double code(double x, double y) {
return Math.pow(x, 4.0);
}
def code(x, y): return math.pow(x, 4.0)
function code(x, y) return x ^ 4.0 end
function tmp = code(x, y) tmp = x ^ 4.0; end
code[x_, y_] := N[Power[x, 4.0], $MachinePrecision]
{x}^{4}
Initial program 85.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-pow.f6458.3%
Applied rewrites58.3%
Taylor expanded in x around inf
lower-pow.f6456.8%
Applied rewrites56.8%
herbie shell --seed 2025223
(FPCore (x y)
:name "Radioactive exchange between two surfaces"
:precision binary64
(- (pow x 4.0) (pow y 4.0)))