
(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}
Sampling outcomes in binary64 precision:
Herbie found 9 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}
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= y_m 8e-250) (fma (/ z (* t t)) z (* (/ x y_m) (/ x y_m))) (fma (/ (/ x y_m) y_m) x (* (/ z t) (/ z t)))))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (y_m <= 8e-250) {
tmp = fma((z / (t * t)), z, ((x / y_m) * (x / y_m)));
} else {
tmp = fma(((x / y_m) / y_m), x, ((z / t) * (z / t)));
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (y_m <= 8e-250) tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / y_m) * Float64(x / y_m))); else tmp = fma(Float64(Float64(x / y_m) / y_m), x, Float64(Float64(z / t) * Float64(z / t))); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[y$95$m, 8e-250], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / y$95$m), $MachinePrecision] * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y$95$m), $MachinePrecision] / y$95$m), $MachinePrecision] * x + N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 8 \cdot 10^{-250}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y\_m} \cdot \frac{x}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{x}{y\_m}}{y\_m}, x, \frac{z}{t} \cdot \frac{z}{t}\right)\\
\end{array}
\end{array}
if y < 8.0000000000000004e-250Initial program 64.3%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6499.8
Applied rewrites99.8%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6488.9
Applied rewrites88.9%
if 8.0000000000000004e-250 < y Initial program 64.5%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6497.3
Applied rewrites97.3%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6497.3
Applied rewrites97.3%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1 (/ (* z z) (* t t))))
(if (or (<= t_1 5e-316) (not (<= t_1 INFINITY)))
(/ (* (/ x y_m) x) y_m)
(+ (* (/ x (* y_m y_m)) x) t_1))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = (z * z) / (t * t);
double tmp;
if ((t_1 <= 5e-316) || !(t_1 <= ((double) INFINITY))) {
tmp = ((x / y_m) * x) / y_m;
} else {
tmp = ((x / (y_m * y_m)) * x) + t_1;
}
return tmp;
}
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
double t_1 = (z * z) / (t * t);
double tmp;
if ((t_1 <= 5e-316) || !(t_1 <= Double.POSITIVE_INFINITY)) {
tmp = ((x / y_m) * x) / y_m;
} else {
tmp = ((x / (y_m * y_m)) * x) + t_1;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z, t): t_1 = (z * z) / (t * t) tmp = 0 if (t_1 <= 5e-316) or not (t_1 <= math.inf): tmp = ((x / y_m) * x) / y_m else: tmp = ((x / (y_m * y_m)) * x) + t_1 return tmp
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(Float64(z * z) / Float64(t * t)) tmp = 0.0 if ((t_1 <= 5e-316) || !(t_1 <= Inf)) tmp = Float64(Float64(Float64(x / y_m) * x) / y_m); else tmp = Float64(Float64(Float64(x / Float64(y_m * y_m)) * x) + t_1); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z, t) t_1 = (z * z) / (t * t); tmp = 0.0; if ((t_1 <= 5e-316) || ~((t_1 <= Inf))) tmp = ((x / y_m) * x) / y_m; else tmp = ((x / (y_m * y_m)) * x) + t_1; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 5e-316], N[Not[LessEqual[t$95$1, Infinity]], $MachinePrecision]], N[(N[(N[(x / y$95$m), $MachinePrecision] * x), $MachinePrecision] / y$95$m), $MachinePrecision], N[(N[(N[(x / N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] + t$95$1), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \frac{z \cdot z}{t \cdot t}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{-316} \lor \neg \left(t\_1 \leq \infty\right):\\
\;\;\;\;\frac{\frac{x}{y\_m} \cdot x}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y\_m \cdot y\_m} \cdot x + t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 z z) (*.f64 t t)) < 5.000000017e-316 or +inf.0 < (/.f64 (*.f64 z z) (*.f64 t t)) Initial program 50.2%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/r*N/A
pow2N/A
associate-/r*N/A
frac-addN/A
lower-/.f64N/A
Applied rewrites72.3%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6455.0
Applied rewrites55.0%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6455.5
Applied rewrites55.5%
Taylor expanded in x around inf
pow2N/A
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6474.3
Applied rewrites74.3%
if 5.000000017e-316 < (/.f64 (*.f64 z z) (*.f64 t t)) < +inf.0Initial program 76.5%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6486.2
Applied rewrites86.2%
Final simplification80.7%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1 (/ (* z z) (* t t))))
(if (or (<= t_1 5e-108) (not (<= t_1 INFINITY)))
(/ (* (/ x y_m) x) y_m)
t_1)))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = (z * z) / (t * t);
double tmp;
if ((t_1 <= 5e-108) || !(t_1 <= ((double) INFINITY))) {
tmp = ((x / y_m) * x) / y_m;
} else {
tmp = t_1;
}
return tmp;
}
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
double t_1 = (z * z) / (t * t);
double tmp;
if ((t_1 <= 5e-108) || !(t_1 <= Double.POSITIVE_INFINITY)) {
tmp = ((x / y_m) * x) / y_m;
} else {
tmp = t_1;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z, t): t_1 = (z * z) / (t * t) tmp = 0 if (t_1 <= 5e-108) or not (t_1 <= math.inf): tmp = ((x / y_m) * x) / y_m else: tmp = t_1 return tmp
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(Float64(z * z) / Float64(t * t)) tmp = 0.0 if ((t_1 <= 5e-108) || !(t_1 <= Inf)) tmp = Float64(Float64(Float64(x / y_m) * x) / y_m); else tmp = t_1; end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z, t) t_1 = (z * z) / (t * t); tmp = 0.0; if ((t_1 <= 5e-108) || ~((t_1 <= Inf))) tmp = ((x / y_m) * x) / y_m; else tmp = t_1; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 5e-108], N[Not[LessEqual[t$95$1, Infinity]], $MachinePrecision]], N[(N[(N[(x / y$95$m), $MachinePrecision] * x), $MachinePrecision] / y$95$m), $MachinePrecision], t$95$1]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \frac{z \cdot z}{t \cdot t}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{-108} \lor \neg \left(t\_1 \leq \infty\right):\\
\;\;\;\;\frac{\frac{x}{y\_m} \cdot x}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 z z) (*.f64 t t)) < 5e-108 or +inf.0 < (/.f64 (*.f64 z z) (*.f64 t t)) Initial program 52.3%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/r*N/A
pow2N/A
associate-/r*N/A
frac-addN/A
lower-/.f64N/A
Applied rewrites73.3%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6453.7
Applied rewrites53.7%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6454.2
Applied rewrites54.2%
Taylor expanded in x around inf
pow2N/A
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6473.0
Applied rewrites73.0%
if 5e-108 < (/.f64 (*.f64 z z) (*.f64 t t)) < +inf.0Initial program 77.2%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6496.1
Applied rewrites96.1%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6496.1
Applied rewrites96.1%
Taylor expanded in t around 0
Applied rewrites88.7%
Taylor expanded in x around 0
pow2N/A
lift-*.f6478.1
Applied rewrites78.1%
Final simplification75.5%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1 (/ (* x x) (* y_m y_m))))
(if (<= t_1 5e+34)
(+ t_1 (* (/ z t) (/ z t)))
(fma (/ z (* t t)) z (* (/ x y_m) (/ x y_m))))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = (x * x) / (y_m * y_m);
double tmp;
if (t_1 <= 5e+34) {
tmp = t_1 + ((z / t) * (z / t));
} else {
tmp = fma((z / (t * t)), z, ((x / y_m) * (x / y_m)));
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(Float64(x * x) / Float64(y_m * y_m)) tmp = 0.0 if (t_1 <= 5e+34) tmp = Float64(t_1 + Float64(Float64(z / t) * Float64(z / t))); else tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / y_m) * Float64(x / y_m))); end return tmp end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] / N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e+34], N[(t$95$1 + N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / y$95$m), $MachinePrecision] * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \frac{x \cdot x}{y\_m \cdot y\_m}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{+34}:\\
\;\;\;\;t\_1 + \frac{z}{t} \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y\_m} \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 4.9999999999999998e34Initial program 68.5%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6494.2
Applied rewrites94.2%
if 4.9999999999999998e34 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 60.9%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6499.1
Applied rewrites99.1%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6499.1
Applied rewrites99.1%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6495.7
Applied rewrites95.7%
y_m = (fabs.f64 y)
(FPCore (x y_m z t)
:precision binary64
(let* ((t_1 (/ (* x x) (* y_m y_m))))
(if (<= t_1 5e-46)
(fma (/ (/ z t) t) z t_1)
(fma (/ z (* t t)) z (* (/ x y_m) (/ x y_m))))))y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double t_1 = (x * x) / (y_m * y_m);
double tmp;
if (t_1 <= 5e-46) {
tmp = fma(((z / t) / t), z, t_1);
} else {
tmp = fma((z / (t * t)), z, ((x / y_m) * (x / y_m)));
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) t_1 = Float64(Float64(x * x) / Float64(y_m * y_m)) tmp = 0.0 if (t_1 <= 5e-46) tmp = fma(Float64(Float64(z / t) / t), z, t_1); else tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / y_m) * Float64(x / y_m))); end return tmp end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] / N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e-46], N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + t$95$1), $MachinePrecision], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / y$95$m), $MachinePrecision] * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_1 := \frac{x \cdot x}{y\_m \cdot y\_m}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{-46}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y\_m} \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 4.99999999999999992e-46Initial program 66.8%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6496.1
Applied rewrites96.1%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
times-fracN/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f6490.4
Applied rewrites90.4%
if 4.99999999999999992e-46 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 62.7%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6498.5
Applied rewrites98.5%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6498.5
Applied rewrites98.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6495.3
Applied rewrites95.3%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (fma (/ (/ z t) t) z (* (/ x y_m) (/ x y_m))))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
return fma(((z / t) / t), z, ((x / y_m) * (x / y_m)));
}
y_m = abs(y) function code(x, y_m, z, t) return fma(Float64(Float64(z / t) / t), z, Float64(Float64(x / y_m) * Float64(x / y_m))) end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + N[(N[(x / y$95$m), $MachinePrecision] * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{x}{y\_m} \cdot \frac{x}{y\_m}\right)
\end{array}
Initial program 64.4%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6497.5
Applied rewrites97.5%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6497.5
Applied rewrites97.5%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (if (<= t 4.8e+115) (fma (/ z (* t t)) z (* (fabs x) (/ (fabs x) (* y_m y_m)))) (/ (* (/ x y_m) x) y_m)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
double tmp;
if (t <= 4.8e+115) {
tmp = fma((z / (t * t)), z, (fabs(x) * (fabs(x) / (y_m * y_m))));
} else {
tmp = ((x / y_m) * x) / y_m;
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z, t) tmp = 0.0 if (t <= 4.8e+115) tmp = fma(Float64(z / Float64(t * t)), z, Float64(abs(x) * Float64(abs(x) / Float64(y_m * y_m)))); else tmp = Float64(Float64(Float64(x / y_m) * x) / y_m); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := If[LessEqual[t, 4.8e+115], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[Abs[x], $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] / N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y$95$m), $MachinePrecision] * x), $MachinePrecision] / y$95$m), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;t \leq 4.8 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \left|x\right| \cdot \frac{\left|x\right|}{y\_m \cdot y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y\_m} \cdot x}{y\_m}\\
\end{array}
\end{array}
if t < 4.8000000000000001e115Initial program 66.8%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6497.1
Applied rewrites97.1%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
times-fracN/A
sqr-abs-revN/A
pow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-/.f64N/A
lower-fabs.f64N/A
pow2N/A
lift-*.f6486.5
Applied rewrites86.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6479.1
Applied rewrites79.1%
if 4.8000000000000001e115 < t Initial program 51.9%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/r*N/A
pow2N/A
associate-/r*N/A
frac-addN/A
lower-/.f64N/A
Applied rewrites71.6%
Taylor expanded in x around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6459.3
Applied rewrites59.3%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6459.8
Applied rewrites59.8%
Taylor expanded in x around inf
pow2N/A
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6483.5
Applied rewrites83.5%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (fma (/ z (* t t)) z (* (/ x y_m) (/ x y_m))))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
return fma((z / (t * t)), z, ((x / y_m) * (x / y_m)));
}
y_m = abs(y) function code(x, y_m, z, t) return fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / y_m) * Float64(x / y_m))) end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / y$95$m), $MachinePrecision] * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y\_m} \cdot \frac{x}{y\_m}\right)
\end{array}
Initial program 64.4%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6497.5
Applied rewrites97.5%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6497.5
Applied rewrites97.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6488.8
Applied rewrites88.8%
y_m = (fabs.f64 y) (FPCore (x y_m z t) :precision binary64 (/ (* z z) (* t t)))
y_m = fabs(y);
double code(double x, double y_m, double z, double t) {
return (z * z) / (t * t);
}
y_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, y_m, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (z * z) / (t * t)
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z, double t) {
return (z * z) / (t * t);
}
y_m = math.fabs(y) def code(x, y_m, z, t): return (z * z) / (t * t)
y_m = abs(y) function code(x, y_m, z, t) return Float64(Float64(z * z) / Float64(t * t)) end
y_m = abs(y); function tmp = code(x, y_m, z, t) tmp = (z * z) / (t * t); end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_, t_] := N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\frac{z \cdot z}{t \cdot t}
\end{array}
Initial program 64.4%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
pow2N/A
associate-/l*N/A
*-commutativeN/A
pow2N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
pow2N/A
pow2N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6497.5
Applied rewrites97.5%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6497.5
Applied rewrites97.5%
Taylor expanded in t around 0
Applied rewrites64.1%
Taylor expanded in x around 0
pow2N/A
lift-*.f6445.4
Applied rewrites45.4%
herbie shell --seed 2025085
(FPCore (x y z t)
:name "Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1"
:precision binary64
:alt
(! :herbie-platform default (+ (pow (/ x y) 2) (pow (/ z t) 2)))
(+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))