
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.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(v)
use fmin_fmax_functions
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.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(v)
use fmin_fmax_functions
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
v_m = (fabs.f64 v) (FPCore (v_m) :precision binary64 (acos (/ (fma (* v_m v_m) -5.0 1.0) (fma (- v_m 1.0) v_m (- v_m 1.0)))))
v_m = fabs(v);
double code(double v_m) {
return acos((fma((v_m * v_m), -5.0, 1.0) / fma((v_m - 1.0), v_m, (v_m - 1.0))));
}
v_m = abs(v) function code(v_m) return acos(Float64(fma(Float64(v_m * v_m), -5.0, 1.0) / fma(Float64(v_m - 1.0), v_m, Float64(v_m - 1.0)))) end
v_m = N[Abs[v], $MachinePrecision] code[v$95$m_] := N[ArcCos[N[(N[(N[(v$95$m * v$95$m), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(N[(v$95$m - 1.0), $MachinePrecision] * v$95$m + N[(v$95$m - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|
\\
\cos^{-1} \left(\frac{\mathsf{fma}\left(v\_m \cdot v\_m, -5, 1\right)}{\mathsf{fma}\left(v\_m - 1, v\_m, v\_m - 1\right)}\right)
\end{array}
Initial program 99.2%
lift--.f64N/A
lift-*.f64N/A
difference-of-sqr-1N/A
*-commutativeN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
*-rgt-identity98.8
Applied rewrites98.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-eval98.8
Applied rewrites98.8%
v_m = (fabs.f64 v) (FPCore (v_m) :precision binary64 (acos (/ (fma -5.0 (* v_m v_m) 1.0) (fma v_m v_m -1.0))))
v_m = fabs(v);
double code(double v_m) {
return acos((fma(-5.0, (v_m * v_m), 1.0) / fma(v_m, v_m, -1.0)));
}
v_m = abs(v) function code(v_m) return acos(Float64(fma(-5.0, Float64(v_m * v_m), 1.0) / fma(v_m, v_m, -1.0))) end
v_m = N[Abs[v], $MachinePrecision] code[v$95$m_] := N[ArcCos[N[(N[(-5.0 * N[(v$95$m * v$95$m), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v$95$m * v$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|
\\
\cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v\_m \cdot v\_m, 1\right)}{\mathsf{fma}\left(v\_m, v\_m, -1\right)}\right)
\end{array}
Initial program 99.2%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
metadata-eval99.2
lift--.f64N/A
lift-*.f64N/A
difference-of-sqr-1N/A
difference-of-sqr--1-revN/A
lower-fma.f6499.2
Applied rewrites99.2%
v_m = (fabs.f64 v) (FPCore (v_m) :precision binary64 (- (PI) (acos (fma -4.0 (* v_m v_m) 1.0))))
\begin{array}{l}
v_m = \left|v\right|
\\
\mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(-4, v\_m \cdot v\_m, 1\right)\right)
\end{array}
Initial program 99.2%
Applied rewrites99.2%
Taylor expanded in v around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.8
Applied rewrites98.8%
v_m = (fabs.f64 v) (FPCore (v_m) :precision binary64 (acos (- (* 4.0 (* v_m v_m)) 1.0)))
v_m = fabs(v);
double code(double v_m) {
return acos(((4.0 * (v_m * v_m)) - 1.0));
}
v_m = private
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(v_m)
use fmin_fmax_functions
real(8), intent (in) :: v_m
code = acos(((4.0d0 * (v_m * v_m)) - 1.0d0))
end function
v_m = Math.abs(v);
public static double code(double v_m) {
return Math.acos(((4.0 * (v_m * v_m)) - 1.0));
}
v_m = math.fabs(v) def code(v_m): return math.acos(((4.0 * (v_m * v_m)) - 1.0))
v_m = abs(v) function code(v_m) return acos(Float64(Float64(4.0 * Float64(v_m * v_m)) - 1.0)) end
v_m = abs(v); function tmp = code(v_m) tmp = acos(((4.0 * (v_m * v_m)) - 1.0)); end
v_m = N[Abs[v], $MachinePrecision] code[v$95$m_] := N[ArcCos[N[(N[(4.0 * N[(v$95$m * v$95$m), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|
\\
\cos^{-1} \left(4 \cdot \left(v\_m \cdot v\_m\right) - 1\right)
\end{array}
Initial program 99.2%
Taylor expanded in v around 0
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.8
Applied rewrites98.8%
v_m = (fabs.f64 v) (FPCore (v_m) :precision binary64 (acos -5.0))
v_m = fabs(v);
double code(double v_m) {
return acos(-5.0);
}
v_m = private
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(v_m)
use fmin_fmax_functions
real(8), intent (in) :: v_m
code = acos((-5.0d0))
end function
v_m = Math.abs(v);
public static double code(double v_m) {
return Math.acos(-5.0);
}
v_m = math.fabs(v) def code(v_m): return math.acos(-5.0)
v_m = abs(v) function code(v_m) return acos(-5.0) end
v_m = abs(v); function tmp = code(v_m) tmp = acos(-5.0); end
v_m = N[Abs[v], $MachinePrecision] code[v$95$m_] := N[ArcCos[-5.0], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|
\\
\cos^{-1} -5
\end{array}
Initial program 99.2%
Taylor expanded in v around inf
Applied rewrites0.0%
herbie shell --seed 2025006
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))