
(FPCore (x y z t) :precision binary64 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * x) / (y * y)) + ((z * z) / (t * t))
end function
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * x) / (y * y)) + ((z * z) / (t * t))
end function
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\end{array}
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (if (<= z_m 7.6e+146) (fma (/ x y) (/ x y) (/ (/ (* z_m z_m) t) t)) (fma (/ x y) (/ x y) (* (/ z_m (* t t)) z_m))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double tmp;
if (z_m <= 7.6e+146) {
tmp = fma((x / y), (x / y), (((z_m * z_m) / t) / t));
} else {
tmp = fma((x / y), (x / y), ((z_m / (t * t)) * z_m));
}
return tmp;
}
z_m = abs(z) function code(x, y, z_m, t) tmp = 0.0 if (z_m <= 7.6e+146) tmp = fma(Float64(x / y), Float64(x / y), Float64(Float64(Float64(z_m * z_m) / t) / t)); else tmp = fma(Float64(x / y), Float64(x / y), Float64(Float64(z_m / Float64(t * t)) * z_m)); end return tmp end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := If[LessEqual[z$95$m, 7.6e+146], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(N[(z$95$m * z$95$m), $MachinePrecision] / t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z$95$m / N[(t * t), $MachinePrecision]), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;z\_m \leq 7.6 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{\frac{z\_m \cdot z\_m}{t}}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z\_m}{t \cdot t} \cdot z\_m\right)\\
\end{array}
\end{array}
if z < 7.59999999999999958e146Initial program 66.5%
Applied rewrites81.7%
Applied rewrites89.6%
if 7.59999999999999958e146 < z Initial program 66.5%
Applied rewrites81.7%
Applied rewrites89.7%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (if (<= (/ (* x x) (* y y)) 5e+168) (fma (/ x (* y y)) x (* (/ z_m t) (/ z_m t))) (fma (/ x y) (/ x y) (* (/ z_m (* t t)) z_m))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double tmp;
if (((x * x) / (y * y)) <= 5e+168) {
tmp = fma((x / (y * y)), x, ((z_m / t) * (z_m / t)));
} else {
tmp = fma((x / y), (x / y), ((z_m / (t * t)) * z_m));
}
return tmp;
}
z_m = abs(z) function code(x, y, z_m, t) tmp = 0.0 if (Float64(Float64(x * x) / Float64(y * y)) <= 5e+168) tmp = fma(Float64(x / Float64(y * y)), x, Float64(Float64(z_m / t) * Float64(z_m / t))); else tmp = fma(Float64(x / y), Float64(x / y), Float64(Float64(z_m / Float64(t * t)) * z_m)); end return tmp end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision], 5e+168], N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x + N[(N[(z$95$m / t), $MachinePrecision] * N[(z$95$m / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z$95$m / N[(t * t), $MachinePrecision]), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 5 \cdot 10^{+168}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y \cdot y}, x, \frac{z\_m}{t} \cdot \frac{z\_m}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z\_m}{t \cdot t} \cdot z\_m\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 4.99999999999999967e168Initial program 66.5%
Applied rewrites73.6%
Applied rewrites89.4%
if 4.99999999999999967e168 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 66.5%
Applied rewrites81.7%
Applied rewrites89.7%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (fma (/ x y) (/ x y) (* (/ z_m (* t t)) z_m)))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
return fma((x / y), (x / y), ((z_m / (t * t)) * z_m));
}
z_m = abs(z) function code(x, y, z_m, t) return fma(Float64(x / y), Float64(x / y), Float64(Float64(z_m / Float64(t * t)) * z_m)) end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z$95$m / N[(t * t), $MachinePrecision]), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z\_m}{t \cdot t} \cdot z\_m\right)
\end{array}
Initial program 66.5%
Applied rewrites81.7%
Applied rewrites89.7%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (fma (/ x (* y y)) x (* (/ z_m (* t t)) z_m)))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
return fma((x / (y * y)), x, ((z_m / (t * t)) * z_m));
}
z_m = abs(z) function code(x, y, z_m, t) return fma(Float64(x / Float64(y * y)), x, Float64(Float64(z_m / Float64(t * t)) * z_m)) end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x + N[(N[(z$95$m / N[(t * t), $MachinePrecision]), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
\mathsf{fma}\left(\frac{x}{y \cdot y}, x, \frac{z\_m}{t \cdot t} \cdot z\_m\right)
\end{array}
Initial program 66.5%
Applied rewrites73.6%
Applied rewrites80.7%
herbie shell --seed 2025153
(FPCore (x y z t)
:name "Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1"
:precision binary64
(+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))