
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
x_m = (fabs.f64 x) z_m = (fabs.f64 z) (FPCore (x_m y z_m) :precision binary64 (fma y 0.5 (* (* (/ (- x_m z_m) y) (+ z_m x_m)) 0.5)))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
return fma(y, 0.5, ((((x_m - z_m) / y) * (z_m + x_m)) * 0.5));
}
x_m = abs(x) z_m = abs(z) function code(x_m, y, z_m) return fma(y, 0.5, Float64(Float64(Float64(Float64(x_m - z_m) / y) * Float64(z_m + x_m)) * 0.5)) end
x_m = N[Abs[x], $MachinePrecision] z_m = N[Abs[z], $MachinePrecision] code[x$95$m_, y_, z$95$m_] := N[(y * 0.5 + N[(N[(N[(N[(x$95$m - z$95$m), $MachinePrecision] / y), $MachinePrecision] * N[(z$95$m + x$95$m), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|
\\
\mathsf{fma}\left(y, 0.5, \left(\frac{x\_m - z\_m}{y} \cdot \left(z\_m + x\_m\right)\right) \cdot 0.5\right)
\end{array}
Initial program 66.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites82.5%
lift-/.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-/l*N/A
sub-divN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
sub-divN/A
lower-/.f64N/A
lift--.f6494.8
Applied rewrites94.8%
Applied rewrites93.2%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
+-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-+.f6499.9
Applied rewrites99.9%
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m)
:precision binary64
(let* ((t_0 (/ (- (+ (* x_m x_m) (* y y)) (* z_m z_m)) (* y 2.0))))
(if (<= t_0 -2e-9)
(* -0.5 (/ (* z_m z_m) y))
(if (or (<= t_0 1e+152) (not (<= t_0 1e+262)))
(* 0.5 y)
(/ (* x_m x_m) (+ y y))))))x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
double t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0);
double tmp;
if (t_0 <= -2e-9) {
tmp = -0.5 * ((z_m * z_m) / y);
} else if ((t_0 <= 1e+152) || !(t_0 <= 1e+262)) {
tmp = 0.5 * y;
} else {
tmp = (x_m * x_m) / (y + y);
}
return tmp;
}
x_m = private
z_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(x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: t_0
real(8) :: tmp
t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0d0)
if (t_0 <= (-2d-9)) then
tmp = (-0.5d0) * ((z_m * z_m) / y)
else if ((t_0 <= 1d+152) .or. (.not. (t_0 <= 1d+262))) then
tmp = 0.5d0 * y
else
tmp = (x_m * x_m) / (y + y)
end if
code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
double t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0);
double tmp;
if (t_0 <= -2e-9) {
tmp = -0.5 * ((z_m * z_m) / y);
} else if ((t_0 <= 1e+152) || !(t_0 <= 1e+262)) {
tmp = 0.5 * y;
} else {
tmp = (x_m * x_m) / (y + y);
}
return tmp;
}
x_m = math.fabs(x) z_m = math.fabs(z) def code(x_m, y, z_m): t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0) tmp = 0 if t_0 <= -2e-9: tmp = -0.5 * ((z_m * z_m) / y) elif (t_0 <= 1e+152) or not (t_0 <= 1e+262): tmp = 0.5 * y else: tmp = (x_m * x_m) / (y + y) return tmp
x_m = abs(x) z_m = abs(z) function code(x_m, y, z_m) t_0 = Float64(Float64(Float64(Float64(x_m * x_m) + Float64(y * y)) - Float64(z_m * z_m)) / Float64(y * 2.0)) tmp = 0.0 if (t_0 <= -2e-9) tmp = Float64(-0.5 * Float64(Float64(z_m * z_m) / y)); elseif ((t_0 <= 1e+152) || !(t_0 <= 1e+262)) tmp = Float64(0.5 * y); else tmp = Float64(Float64(x_m * x_m) / Float64(y + y)); end return tmp end
x_m = abs(x); z_m = abs(z); function tmp_2 = code(x_m, y, z_m) t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0); tmp = 0.0; if (t_0 <= -2e-9) tmp = -0.5 * ((z_m * z_m) / y); elseif ((t_0 <= 1e+152) || ~((t_0 <= 1e+262))) tmp = 0.5 * y; else tmp = (x_m * x_m) / (y + y); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-9], N[(-0.5 * N[(N[(z$95$m * z$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$0, 1e+152], N[Not[LessEqual[t$95$0, 1e+262]], $MachinePrecision]], N[(0.5 * y), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|
\\
\begin{array}{l}
t_0 := \frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-9}:\\
\;\;\;\;-0.5 \cdot \frac{z\_m \cdot z\_m}{y}\\
\mathbf{elif}\;t\_0 \leq 10^{+152} \lor \neg \left(t\_0 \leq 10^{+262}\right):\\
\;\;\;\;0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot x\_m}{y + y}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.00000000000000012e-9Initial program 76.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6432.3
Applied rewrites32.3%
if -2.00000000000000012e-9 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 1e152 or 1e262 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 56.6%
Taylor expanded in y around inf
lower-*.f6447.9
Applied rewrites47.9%
if 1e152 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 1e262Initial program 99.7%
Taylor expanded in x around inf
pow2N/A
lift-*.f6440.8
Applied rewrites40.8%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6440.8
Applied rewrites40.8%
Final simplification40.8%
x_m = (fabs.f64 x) z_m = (fabs.f64 z) (FPCore (x_m y z_m) :precision binary64 (if (<= (/ (- (+ (* x_m x_m) (* y y)) (* z_m z_m)) (* y 2.0)) 0.0) (* (* (+ z_m x_m) (/ (- x_m z_m) y)) 0.5) (* 0.5 (+ (/ (* x_m x_m) y) y))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
double tmp;
if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0) {
tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5;
} else {
tmp = 0.5 * (((x_m * x_m) / y) + y);
}
return tmp;
}
x_m = private
z_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(x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0d0)) <= 0.0d0) then
tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5d0
else
tmp = 0.5d0 * (((x_m * x_m) / y) + y)
end if
code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
double tmp;
if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0) {
tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5;
} else {
tmp = 0.5 * (((x_m * x_m) / y) + y);
}
return tmp;
}
x_m = math.fabs(x) z_m = math.fabs(z) def code(x_m, y, z_m): tmp = 0 if ((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0: tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5 else: tmp = 0.5 * (((x_m * x_m) / y) + y) return tmp
x_m = abs(x) z_m = abs(z) function code(x_m, y, z_m) tmp = 0.0 if (Float64(Float64(Float64(Float64(x_m * x_m) + Float64(y * y)) - Float64(z_m * z_m)) / Float64(y * 2.0)) <= 0.0) tmp = Float64(Float64(Float64(z_m + x_m) * Float64(Float64(x_m - z_m) / y)) * 0.5); else tmp = Float64(0.5 * Float64(Float64(Float64(x_m * x_m) / y) + y)); end return tmp end
x_m = abs(x); z_m = abs(z); function tmp_2 = code(x_m, y, z_m) tmp = 0.0; if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0) tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5; else tmp = 0.5 * (((x_m * x_m) / y) + y); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] z_m = N[Abs[z], $MachinePrecision] code[x$95$m_, y_, z$95$m_] := If[LessEqual[N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(z$95$m + x$95$m), $MachinePrecision] * N[(N[(x$95$m - z$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] / y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2} \leq 0:\\
\;\;\;\;\left(\left(z\_m + x\_m\right) \cdot \frac{x\_m - z\_m}{y}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\frac{x\_m \cdot x\_m}{y} + y\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 0.0Initial program 74.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites84.8%
Taylor expanded in y around 0
*-commutativeN/A
pow2N/A
pow2N/A
difference-of-squares-revN/A
lower-*.f64N/A
associate-/l*N/A
sub-divN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
sub-divN/A
lower-/.f64N/A
lift--.f6463.9
Applied rewrites63.9%
if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 60.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites80.5%
lift-/.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-/l*N/A
sub-divN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
sub-divN/A
lower-/.f64N/A
lift--.f6494.4
Applied rewrites94.4%
Applied rewrites93.0%
Taylor expanded in z around 0
Applied rewrites64.2%
x_m = (fabs.f64 x) z_m = (fabs.f64 z) (FPCore (x_m y z_m) :precision binary64 (if (<= (/ (- (+ (* x_m x_m) (* y y)) (* z_m z_m)) (* y 2.0)) -2e-9) (* -0.5 (/ (* z_m z_m) y)) (* 0.5 (+ (/ (* x_m x_m) y) y))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
double tmp;
if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9) {
tmp = -0.5 * ((z_m * z_m) / y);
} else {
tmp = 0.5 * (((x_m * x_m) / y) + y);
}
return tmp;
}
x_m = private
z_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(x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0d0)) <= (-2d-9)) then
tmp = (-0.5d0) * ((z_m * z_m) / y)
else
tmp = 0.5d0 * (((x_m * x_m) / y) + y)
end if
code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
double tmp;
if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9) {
tmp = -0.5 * ((z_m * z_m) / y);
} else {
tmp = 0.5 * (((x_m * x_m) / y) + y);
}
return tmp;
}
x_m = math.fabs(x) z_m = math.fabs(z) def code(x_m, y, z_m): tmp = 0 if ((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9: tmp = -0.5 * ((z_m * z_m) / y) else: tmp = 0.5 * (((x_m * x_m) / y) + y) return tmp
x_m = abs(x) z_m = abs(z) function code(x_m, y, z_m) tmp = 0.0 if (Float64(Float64(Float64(Float64(x_m * x_m) + Float64(y * y)) - Float64(z_m * z_m)) / Float64(y * 2.0)) <= -2e-9) tmp = Float64(-0.5 * Float64(Float64(z_m * z_m) / y)); else tmp = Float64(0.5 * Float64(Float64(Float64(x_m * x_m) / y) + y)); end return tmp end
x_m = abs(x); z_m = abs(z); function tmp_2 = code(x_m, y, z_m) tmp = 0.0; if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9) tmp = -0.5 * ((z_m * z_m) / y); else tmp = 0.5 * (((x_m * x_m) / y) + y); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] z_m = N[Abs[z], $MachinePrecision] code[x$95$m_, y_, z$95$m_] := If[LessEqual[N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], -2e-9], N[(-0.5 * N[(N[(z$95$m * z$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] / y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2} \leq -2 \cdot 10^{-9}:\\
\;\;\;\;-0.5 \cdot \frac{z\_m \cdot z\_m}{y}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\frac{x\_m \cdot x\_m}{y} + y\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.00000000000000012e-9Initial program 76.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6432.3
Applied rewrites32.3%
if -2.00000000000000012e-9 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 59.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.8%
lift-/.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-/l*N/A
sub-divN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
sub-divN/A
lower-/.f64N/A
lift--.f6494.6
Applied rewrites94.6%
Applied rewrites92.0%
Taylor expanded in z around 0
Applied rewrites64.3%
x_m = (fabs.f64 x) z_m = (fabs.f64 z) (FPCore (x_m y z_m) :precision binary64 (if (<= x_m 4e+89) (* 0.5 y) (/ (* x_m x_m) (+ y y))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
double tmp;
if (x_m <= 4e+89) {
tmp = 0.5 * y;
} else {
tmp = (x_m * x_m) / (y + y);
}
return tmp;
}
x_m = private
z_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(x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if (x_m <= 4d+89) then
tmp = 0.5d0 * y
else
tmp = (x_m * x_m) / (y + y)
end if
code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
double tmp;
if (x_m <= 4e+89) {
tmp = 0.5 * y;
} else {
tmp = (x_m * x_m) / (y + y);
}
return tmp;
}
x_m = math.fabs(x) z_m = math.fabs(z) def code(x_m, y, z_m): tmp = 0 if x_m <= 4e+89: tmp = 0.5 * y else: tmp = (x_m * x_m) / (y + y) return tmp
x_m = abs(x) z_m = abs(z) function code(x_m, y, z_m) tmp = 0.0 if (x_m <= 4e+89) tmp = Float64(0.5 * y); else tmp = Float64(Float64(x_m * x_m) / Float64(y + y)); end return tmp end
x_m = abs(x); z_m = abs(z); function tmp_2 = code(x_m, y, z_m) tmp = 0.0; if (x_m <= 4e+89) tmp = 0.5 * y; else tmp = (x_m * x_m) / (y + y); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] z_m = N[Abs[z], $MachinePrecision] code[x$95$m_, y_, z$95$m_] := If[LessEqual[x$95$m, 4e+89], N[(0.5 * y), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 4 \cdot 10^{+89}:\\
\;\;\;\;0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot x\_m}{y + y}\\
\end{array}
\end{array}
if x < 3.99999999999999998e89Initial program 65.1%
Taylor expanded in y around inf
lower-*.f6446.6
Applied rewrites46.6%
if 3.99999999999999998e89 < x Initial program 73.2%
Taylor expanded in x around inf
pow2N/A
lift-*.f6463.1
Applied rewrites63.1%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6463.1
Applied rewrites63.1%
x_m = (fabs.f64 x) z_m = (fabs.f64 z) (FPCore (x_m y z_m) :precision binary64 (* 0.5 y))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
return 0.5 * y;
}
x_m = private
z_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(x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
code = 0.5d0 * y
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
return 0.5 * y;
}
x_m = math.fabs(x) z_m = math.fabs(z) def code(x_m, y, z_m): return 0.5 * y
x_m = abs(x) z_m = abs(z) function code(x_m, y, z_m) return Float64(0.5 * y) end
x_m = abs(x); z_m = abs(z); function tmp = code(x_m, y, z_m) tmp = 0.5 * y; end
x_m = N[Abs[x], $MachinePrecision] z_m = N[Abs[z], $MachinePrecision] code[x$95$m_, y_, z$95$m_] := N[(0.5 * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|
\\
0.5 \cdot y
\end{array}
Initial program 66.7%
Taylor expanded in y around inf
lower-*.f6440.4
Applied rewrites40.4%
(FPCore (x y z) :precision binary64 (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x))))
double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * 0.5d0) - (((0.5d0 / y) * (z + x)) * (z - x))
end function
public static double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
def code(x, y, z): return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x))
function code(x, y, z) return Float64(Float64(y * 0.5) - Float64(Float64(Float64(0.5 / y) * Float64(z + x)) * Float64(z - x))) end
function tmp = code(x, y, z) tmp = (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x)); end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] - N[(N[(N[(0.5 / y), $MachinePrecision] * N[(z + x), $MachinePrecision]), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)
\end{array}
herbie shell --seed 2025051
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:alt
(! :herbie-platform default (- (* y 1/2) (* (* (/ 1/2 y) (+ z x)) (- z x))))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))