
(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}
(FPCore (x y z t) :precision binary64 (fma (/ (/ z t) t) z (* (/ x y) (/ x y))))
double code(double x, double y, double z, double t) {
return fma(((z / t) / t), z, ((x / y) * (x / y)));
}
function code(x, y, z, t) return fma(Float64(Float64(z / t) / t), z, Float64(Float64(x / y) * Float64(x / y))) end
code[x_, y_, z_, t_] := N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{x}{y} \cdot \frac{x}{y}\right)
\end{array}
Initial program 64.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6478.5
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6497.9
Applied rewrites97.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6497.9
Applied rewrites97.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (* x x) (* y y))))
(if (or (<= t_1 0.0) (not (<= t_1 INFINITY)))
(* (/ z t) (/ z t))
(fma (/ z (* t t)) z (* (/ x (* y y)) x)))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) / (y * y);
double tmp;
if ((t_1 <= 0.0) || !(t_1 <= ((double) INFINITY))) {
tmp = (z / t) * (z / t);
} else {
tmp = fma((z / (t * t)), z, ((x / (y * y)) * x));
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x * x) / Float64(y * y)) tmp = 0.0 if ((t_1 <= 0.0) || !(t_1 <= Inf)) tmp = Float64(Float64(z / t) * Float64(z / t)); else tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / Float64(y * y)) * x)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, Infinity]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x \cdot x}{y \cdot y}\\
\mathbf{if}\;t\_1 \leq 0 \lor \neg \left(t\_1 \leq \infty\right):\\
\;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y \cdot y} \cdot x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 0.0 or +inf.0 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 51.9%
Taylor expanded in x around 0
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
Applied rewrites82.7%
if 0.0 < (/.f64 (*.f64 x x) (*.f64 y y)) < +inf.0Initial program 77.2%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
unpow2N/A
associate-*l/N/A
associate-/l*N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6498.3
Applied rewrites98.3%
Applied rewrites95.5%
Applied rewrites93.4%
Final simplification88.0%
(FPCore (x y z t) :precision binary64 (if (<= (/ (* z z) (* t t)) INFINITY) (fma (/ z (* t t)) z (* (/ x y) (/ x y))) (+ (/ (* x x) (* y y)) (* (/ z t) (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) / (t * t)) <= ((double) INFINITY)) {
tmp = fma((z / (t * t)), z, ((x / y) * (x / y)));
} else {
tmp = ((x * x) / (y * y)) + ((z / t) * (z / t));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(z * z) / Float64(t * t)) <= Inf) tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / y) * Float64(x / y))); else tmp = Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z / t) * Float64(z / t))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{z \cdot z}{t \cdot t} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y} \cdot \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{y \cdot y} + \frac{z}{t} \cdot \frac{z}{t}\\
\end{array}
\end{array}
if (/.f64 (*.f64 z z) (*.f64 t t)) < +inf.0Initial program 73.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6478.8
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6498.9
Applied rewrites98.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6498.9
Applied rewrites98.9%
lift-/.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
lift-/.f6497.7
Applied rewrites97.7%
if +inf.0 < (/.f64 (*.f64 z z) (*.f64 t t)) Initial program 0.0%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
(FPCore (x y z t) :precision binary64 (if (<= (/ (* x x) (* y y)) 2e+119) (fma (/ (/ z t) t) z (* (/ x (* y y)) x)) (fma (/ z (* t t)) z (* (/ x y) (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) / (y * y)) <= 2e+119) {
tmp = fma(((z / t) / t), z, ((x / (y * y)) * x));
} else {
tmp = fma((z / (t * t)), z, ((x / y) * (x / y)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(x * x) / Float64(y * y)) <= 2e+119) tmp = fma(Float64(Float64(z / t) / t), z, Float64(Float64(x / Float64(y * y)) * x)); else tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(x / y) * Float64(x / y))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision], 2e+119], N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 2 \cdot 10^{+119}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{x}{y \cdot y} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{x}{y} \cdot \frac{x}{y}\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 1.99999999999999989e119Initial program 71.1%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
unpow2N/A
associate-*l/N/A
associate-/l*N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6496.3
Applied rewrites96.3%
Applied rewrites95.3%
if 1.99999999999999989e119 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 58.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6464.9
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f6498.3
Applied rewrites98.3%
lift-pow.f64N/A
unpow2N/A
lower-*.f6498.3
Applied rewrites98.3%
lift-/.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
lift-/.f6496.2
Applied rewrites96.2%
(FPCore (x y z t) :precision binary64 (if (<= (/ (* x x) (* y y)) 2e+119) (fma (/ (/ z t) t) z (* (/ x (* y y)) x)) (fma (/ z (* t t)) z (* (/ (/ x y) y) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) / (y * y)) <= 2e+119) {
tmp = fma(((z / t) / t), z, ((x / (y * y)) * x));
} else {
tmp = fma((z / (t * t)), z, (((x / y) / y) * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(x * x) / Float64(y * y)) <= 2e+119) tmp = fma(Float64(Float64(z / t) / t), z, Float64(Float64(x / Float64(y * y)) * x)); else tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(Float64(x / y) / y) * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision], 2e+119], N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 2 \cdot 10^{+119}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{x}{y \cdot y} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{\frac{x}{y}}{y} \cdot x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 1.99999999999999989e119Initial program 71.1%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
unpow2N/A
associate-*l/N/A
associate-/l*N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6496.3
Applied rewrites96.3%
Applied rewrites95.3%
if 1.99999999999999989e119 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 58.4%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
unpow2N/A
associate-*l/N/A
associate-/l*N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6494.7
Applied rewrites94.7%
Applied rewrites92.6%
(FPCore (x y z t) :precision binary64 (if (<= (/ (* x x) (* y y)) 0.0) (* (/ z t) (/ z t)) (fma (/ z (* t t)) z (* (/ (/ x y) y) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) / (y * y)) <= 0.0) {
tmp = (z / t) * (z / t);
} else {
tmp = fma((z / (t * t)), z, (((x / y) / y) * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(x * x) / Float64(y * y)) <= 0.0) tmp = Float64(Float64(z / t) * Float64(z / t)); else tmp = fma(Float64(z / Float64(t * t)), z, Float64(Float64(Float64(x / y) / y) * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z + N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 0:\\
\;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t \cdot t}, z, \frac{\frac{x}{y}}{y} \cdot x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < 0.0Initial program 68.4%
Taylor expanded in x around 0
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6491.2
Applied rewrites91.2%
Applied rewrites93.9%
if 0.0 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 62.2%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
unpow2N/A
associate-*l/N/A
associate-/l*N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6495.5
Applied rewrites95.5%
Applied rewrites92.1%
(FPCore (x y z t) :precision binary64 (fma (/ (/ z t) t) z (* (/ (/ x y) y) x)))
double code(double x, double y, double z, double t) {
return fma(((z / t) / t), z, (((x / y) / y) * x));
}
function code(x, y, z, t) return fma(Float64(Float64(z / t) / t), z, Float64(Float64(Float64(x / y) / y) * x)) end
code[x_, y_, z_, t_] := N[(N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] * z + N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\frac{z}{t}}{t}, z, \frac{\frac{x}{y}}{y} \cdot x\right)
\end{array}
Initial program 64.5%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-/l*N/A
unpow2N/A
associate-*l/N/A
associate-/l*N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6495.5
Applied rewrites95.5%
(FPCore (x y z t) :precision binary64 (if (<= y 1.9e-72) (* (/ z (* t t)) z) (* (/ z t) (/ z t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e-72) {
tmp = (z / (t * t)) * z;
} else {
tmp = (z / t) * (z / t);
}
return tmp;
}
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
real(8) :: tmp
if (y <= 1.9d-72) then
tmp = (z / (t * t)) * z
else
tmp = (z / t) * (z / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e-72) {
tmp = (z / (t * t)) * z;
} else {
tmp = (z / t) * (z / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.9e-72: tmp = (z / (t * t)) * z else: tmp = (z / t) * (z / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.9e-72) tmp = Float64(Float64(z / Float64(t * t)) * z); else tmp = Float64(Float64(z / t) * Float64(z / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.9e-72) tmp = (z / (t * t)) * z; else tmp = (z / t) * (z / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.9e-72], N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-72}:\\
\;\;\;\;\frac{z}{t \cdot t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\
\end{array}
\end{array}
if y < 1.90000000000000001e-72Initial program 65.2%
Taylor expanded in x around 0
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6454.2
Applied rewrites54.2%
Applied rewrites53.5%
if 1.90000000000000001e-72 < y Initial program 63.3%
Taylor expanded in x around 0
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6468.7
Applied rewrites68.7%
Applied rewrites70.5%
(FPCore (x y z t) :precision binary64 (* (/ z (* t t)) z))
double code(double x, double y, double z, double t) {
return (z / (t * t)) * z;
}
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 = (z / (t * t)) * z
end function
public static double code(double x, double y, double z, double t) {
return (z / (t * t)) * z;
}
def code(x, y, z, t): return (z / (t * t)) * z
function code(x, y, z, t) return Float64(Float64(z / Float64(t * t)) * z) end
function tmp = code(x, y, z, t) tmp = (z / (t * t)) * z; end
code[x_, y_, z_, t_] := N[(N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\frac{z}{t \cdot t} \cdot z
\end{array}
Initial program 64.5%
Taylor expanded in x around 0
unpow2N/A
associate-*l/N/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6459.5
Applied rewrites59.5%
Applied rewrites55.5%
(FPCore (x y z t) :precision binary64 (+ (pow (/ x y) 2.0) (pow (/ z t) 2.0)))
double code(double x, double y, double z, double t) {
return pow((x / y), 2.0) + pow((z / t), 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, 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 / y) ** 2.0d0) + ((z / t) ** 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return Math.pow((x / y), 2.0) + Math.pow((z / t), 2.0);
}
def code(x, y, z, t): return math.pow((x / y), 2.0) + math.pow((z / t), 2.0)
function code(x, y, z, t) return Float64((Float64(x / y) ^ 2.0) + (Float64(z / t) ^ 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x / y) ^ 2.0) + ((z / t) ^ 2.0); end
code[x_, y_, z_, t_] := N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(z / t), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{x}{y}\right)}^{2} + {\left(\frac{z}{t}\right)}^{2}
\end{array}
herbie shell --seed 2024358
(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))))