
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (/ x (/ z (+ z y))))
double code(double x, double y, double z) {
return x / (z / (z + y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / (z / (z + y))
end function
public static double code(double x, double y, double z) {
return x / (z / (z + y));
}
def code(x, y, z): return x / (z / (z + y))
function code(x, y, z) return Float64(x / Float64(z / Float64(z + y))) end
function tmp = code(x, y, z) tmp = x / (z / (z + y)); end
code[x_, y_, z_] := N[(x / N[(z / N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{z + y}}
\end{array}
Initial program 85.1%
associate-/l*95.7%
Simplified95.7%
Final simplification95.7%
(FPCore (x y z)
:precision binary64
(if (<= z -1.4e+15)
x
(if (or (<= z -4.9e-61) (and (not (<= z -2.05e-122)) (<= z 1.5e+98)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+15) {
tmp = x;
} else if ((z <= -4.9e-61) || (!(z <= -2.05e-122) && (z <= 1.5e+98))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.4d+15)) then
tmp = x
else if ((z <= (-4.9d-61)) .or. (.not. (z <= (-2.05d-122))) .and. (z <= 1.5d+98)) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+15) {
tmp = x;
} else if ((z <= -4.9e-61) || (!(z <= -2.05e-122) && (z <= 1.5e+98))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+15: tmp = x elif (z <= -4.9e-61) or (not (z <= -2.05e-122) and (z <= 1.5e+98)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+15) tmp = x; elseif ((z <= -4.9e-61) || (!(z <= -2.05e-122) && (z <= 1.5e+98))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+15) tmp = x; elseif ((z <= -4.9e-61) || (~((z <= -2.05e-122)) && (z <= 1.5e+98))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+15], x, If[Or[LessEqual[z, -4.9e-61], And[N[Not[LessEqual[z, -2.05e-122]], $MachinePrecision], LessEqual[z, 1.5e+98]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.9 \cdot 10^{-61} \lor \neg \left(z \leq -2.05 \cdot 10^{-122}\right) \land z \leq 1.5 \cdot 10^{+98}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.4e15 or -4.90000000000000002e-61 < z < -2.05e-122 or 1.5000000000000001e98 < z Initial program 77.0%
associate-*r/98.3%
Simplified98.3%
Taylor expanded in y around 0 80.1%
if -1.4e15 < z < -4.90000000000000002e-61 or -2.05e-122 < z < 1.5000000000000001e98Initial program 91.1%
associate-*r/93.4%
Simplified93.4%
Taylor expanded in y around inf 73.7%
Final simplification76.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (/ x z))))
(if (<= y -3.8e-86)
t_0
(if (<= y 3.2e-83)
x
(if (<= y 1.35e-16) (* x (/ y z)) (if (<= y 1.15) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -3.8e-86) {
tmp = t_0;
} else if (y <= 3.2e-83) {
tmp = x;
} else if (y <= 1.35e-16) {
tmp = x * (y / z);
} else if (y <= 1.15) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * (x / z)
if (y <= (-3.8d-86)) then
tmp = t_0
else if (y <= 3.2d-83) then
tmp = x
else if (y <= 1.35d-16) then
tmp = x * (y / z)
else if (y <= 1.15d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -3.8e-86) {
tmp = t_0;
} else if (y <= 3.2e-83) {
tmp = x;
} else if (y <= 1.35e-16) {
tmp = x * (y / z);
} else if (y <= 1.15) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x / z) tmp = 0 if y <= -3.8e-86: tmp = t_0 elif y <= 3.2e-83: tmp = x elif y <= 1.35e-16: tmp = x * (y / z) elif y <= 1.15: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x / z)) tmp = 0.0 if (y <= -3.8e-86) tmp = t_0; elseif (y <= 3.2e-83) tmp = x; elseif (y <= 1.35e-16) tmp = Float64(x * Float64(y / z)); elseif (y <= 1.15) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x / z); tmp = 0.0; if (y <= -3.8e-86) tmp = t_0; elseif (y <= 3.2e-83) tmp = x; elseif (y <= 1.35e-16) tmp = x * (y / z); elseif (y <= 1.15) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.8e-86], t$95$0, If[LessEqual[y, 3.2e-83], x, If[LessEqual[y, 1.35e-16], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -3.8 \cdot 10^{-86}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-83}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-16}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 1.15:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.8e-86 or 1.1499999999999999 < y Initial program 90.7%
associate-*r/91.9%
Simplified91.9%
Taylor expanded in y around inf 74.6%
associate-*r/76.4%
Simplified76.4%
if -3.8e-86 < y < 3.2000000000000001e-83 or 1.35e-16 < y < 1.1499999999999999Initial program 75.8%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 80.3%
if 3.2000000000000001e-83 < y < 1.35e-16Initial program 99.7%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around inf 69.5%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (* x (/ (+ z y) z)))
double code(double x, double y, double z) {
return x * ((z + y) / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * ((z + y) / z)
end function
public static double code(double x, double y, double z) {
return x * ((z + y) / z);
}
def code(x, y, z): return x * ((z + y) / z)
function code(x, y, z) return Float64(x * Float64(Float64(z + y) / z)) end
function tmp = code(x, y, z) tmp = x * ((z + y) / z); end
code[x_, y_, z_] := N[(x * N[(N[(z + y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{z + y}{z}
\end{array}
Initial program 85.1%
associate-*r/95.5%
Simplified95.5%
Final simplification95.5%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 85.1%
associate-*r/95.5%
Simplified95.5%
Taylor expanded in y around 0 46.3%
Final simplification46.3%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (y + z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2023268
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))