
(FPCore (a b) :precision binary64 (- (* (* (* a a) b) b)))
double code(double a, double b) {
return -(((a * a) * b) * b);
}
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)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -(((a * a) * b) * b)
end function
public static double code(double a, double b) {
return -(((a * a) * b) * b);
}
def code(a, b): return -(((a * a) * b) * b)
function code(a, b) return Float64(-Float64(Float64(Float64(a * a) * b) * b)) end
function tmp = code(a, b) tmp = -(((a * a) * b) * b); end
code[a_, b_] := (-N[(N[(N[(a * a), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision])
\begin{array}{l}
\\
-\left(\left(a \cdot a\right) \cdot b\right) \cdot b
\end{array}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (- (* (* (* a a) b) b)))
double code(double a, double b) {
return -(((a * a) * b) * b);
}
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)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -(((a * a) * b) * b)
end function
public static double code(double a, double b) {
return -(((a * a) * b) * b);
}
def code(a, b): return -(((a * a) * b) * b)
function code(a, b) return Float64(-Float64(Float64(Float64(a * a) * b) * b)) end
function tmp = code(a, b) tmp = -(((a * a) * b) * b); end
code[a_, b_] := (-N[(N[(N[(a * a), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision])
\begin{array}{l}
\\
-\left(\left(a \cdot a\right) \cdot b\right) \cdot b
\end{array}
a_m = (fabs.f64 a) b_m = (fabs.f64 b) NOTE: a_m and b_m should be sorted in increasing order before calling this function. (FPCore (a_m b_m) :precision binary64 (if (<= a_m 3.35e-155) (* (- a_m) (* (* b_m a_m) b_m)) (- (* (* (* a_m a_m) b_m) b_m))))
a_m = fabs(a);
b_m = fabs(b);
assert(a_m < b_m);
double code(double a_m, double b_m) {
double tmp;
if (a_m <= 3.35e-155) {
tmp = -a_m * ((b_m * a_m) * b_m);
} else {
tmp = -(((a_m * a_m) * b_m) * b_m);
}
return tmp;
}
a_m = private
b_m = private
NOTE: a_m and b_m 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_m, b_m)
use fmin_fmax_functions
real(8), intent (in) :: a_m
real(8), intent (in) :: b_m
real(8) :: tmp
if (a_m <= 3.35d-155) then
tmp = -a_m * ((b_m * a_m) * b_m)
else
tmp = -(((a_m * a_m) * b_m) * b_m)
end if
code = tmp
end function
a_m = Math.abs(a);
b_m = Math.abs(b);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
double tmp;
if (a_m <= 3.35e-155) {
tmp = -a_m * ((b_m * a_m) * b_m);
} else {
tmp = -(((a_m * a_m) * b_m) * b_m);
}
return tmp;
}
a_m = math.fabs(a) b_m = math.fabs(b) [a_m, b_m] = sort([a_m, b_m]) def code(a_m, b_m): tmp = 0 if a_m <= 3.35e-155: tmp = -a_m * ((b_m * a_m) * b_m) else: tmp = -(((a_m * a_m) * b_m) * b_m) return tmp
a_m = abs(a) b_m = abs(b) a_m, b_m = sort([a_m, b_m]) function code(a_m, b_m) tmp = 0.0 if (a_m <= 3.35e-155) tmp = Float64(Float64(-a_m) * Float64(Float64(b_m * a_m) * b_m)); else tmp = Float64(-Float64(Float64(Float64(a_m * a_m) * b_m) * b_m)); end return tmp end
a_m = abs(a);
b_m = abs(b);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp_2 = code(a_m, b_m)
tmp = 0.0;
if (a_m <= 3.35e-155)
tmp = -a_m * ((b_m * a_m) * b_m);
else
tmp = -(((a_m * a_m) * b_m) * b_m);
end
tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision] b_m = N[Abs[b], $MachinePrecision] NOTE: a_m and b_m should be sorted in increasing order before calling this function. code[a$95$m_, b$95$m_] := If[LessEqual[a$95$m, 3.35e-155], N[((-a$95$m) * N[(N[(b$95$m * a$95$m), $MachinePrecision] * b$95$m), $MachinePrecision]), $MachinePrecision], (-N[(N[(N[(a$95$m * a$95$m), $MachinePrecision] * b$95$m), $MachinePrecision] * b$95$m), $MachinePrecision])]
\begin{array}{l}
a_m = \left|a\right|
\\
b_m = \left|b\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 3.35 \cdot 10^{-155}:\\
\;\;\;\;\left(-a\_m\right) \cdot \left(\left(b\_m \cdot a\_m\right) \cdot b\_m\right)\\
\mathbf{else}:\\
\;\;\;\;-\left(\left(a\_m \cdot a\_m\right) \cdot b\_m\right) \cdot b\_m\\
\end{array}
\end{array}
if a < 3.35000000000000014e-155Initial program 81.9%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6494.1
Applied rewrites94.1%
if 3.35000000000000014e-155 < a Initial program 81.9%
a_m = (fabs.f64 a) b_m = (fabs.f64 b) NOTE: a_m and b_m should be sorted in increasing order before calling this function. (FPCore (a_m b_m) :precision binary64 (* (* (- b_m) a_m) (* b_m a_m)))
a_m = fabs(a);
b_m = fabs(b);
assert(a_m < b_m);
double code(double a_m, double b_m) {
return (-b_m * a_m) * (b_m * a_m);
}
a_m = private
b_m = private
NOTE: a_m and b_m 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_m, b_m)
use fmin_fmax_functions
real(8), intent (in) :: a_m
real(8), intent (in) :: b_m
code = (-b_m * a_m) * (b_m * a_m)
end function
a_m = Math.abs(a);
b_m = Math.abs(b);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
return (-b_m * a_m) * (b_m * a_m);
}
a_m = math.fabs(a) b_m = math.fabs(b) [a_m, b_m] = sort([a_m, b_m]) def code(a_m, b_m): return (-b_m * a_m) * (b_m * a_m)
a_m = abs(a) b_m = abs(b) a_m, b_m = sort([a_m, b_m]) function code(a_m, b_m) return Float64(Float64(Float64(-b_m) * a_m) * Float64(b_m * a_m)) end
a_m = abs(a);
b_m = abs(b);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
tmp = (-b_m * a_m) * (b_m * a_m);
end
a_m = N[Abs[a], $MachinePrecision] b_m = N[Abs[b], $MachinePrecision] NOTE: a_m and b_m should be sorted in increasing order before calling this function. code[a$95$m_, b$95$m_] := N[(N[((-b$95$m) * a$95$m), $MachinePrecision] * N[(b$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
b_m = \left|b\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\left(\left(-b\_m\right) \cdot a\_m\right) \cdot \left(b\_m \cdot a\_m\right)
\end{array}
Initial program 81.9%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
lower-*.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
a_m = (fabs.f64 a) b_m = (fabs.f64 b) NOTE: a_m and b_m should be sorted in increasing order before calling this function. (FPCore (a_m b_m) :precision binary64 (- (* (* (* a_m a_m) b_m) b_m)))
a_m = fabs(a);
b_m = fabs(b);
assert(a_m < b_m);
double code(double a_m, double b_m) {
return -(((a_m * a_m) * b_m) * b_m);
}
a_m = private
b_m = private
NOTE: a_m and b_m 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_m, b_m)
use fmin_fmax_functions
real(8), intent (in) :: a_m
real(8), intent (in) :: b_m
code = -(((a_m * a_m) * b_m) * b_m)
end function
a_m = Math.abs(a);
b_m = Math.abs(b);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
return -(((a_m * a_m) * b_m) * b_m);
}
a_m = math.fabs(a) b_m = math.fabs(b) [a_m, b_m] = sort([a_m, b_m]) def code(a_m, b_m): return -(((a_m * a_m) * b_m) * b_m)
a_m = abs(a) b_m = abs(b) a_m, b_m = sort([a_m, b_m]) function code(a_m, b_m) return Float64(-Float64(Float64(Float64(a_m * a_m) * b_m) * b_m)) end
a_m = abs(a);
b_m = abs(b);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
tmp = -(((a_m * a_m) * b_m) * b_m);
end
a_m = N[Abs[a], $MachinePrecision] b_m = N[Abs[b], $MachinePrecision] NOTE: a_m and b_m should be sorted in increasing order before calling this function. code[a$95$m_, b$95$m_] := (-N[(N[(N[(a$95$m * a$95$m), $MachinePrecision] * b$95$m), $MachinePrecision] * b$95$m), $MachinePrecision])
\begin{array}{l}
a_m = \left|a\right|
\\
b_m = \left|b\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
-\left(\left(a\_m \cdot a\_m\right) \cdot b\_m\right) \cdot b\_m
\end{array}
Initial program 81.9%
herbie shell --seed 2025149
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))