
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / 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 * (sin(y) / y)) / z
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / 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 * (sin(y) / y)) / z
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (sin y) y)) (t_1 (/ (* x t_0) z)))
(if (<= t_1 -1e-55)
(/ x (/ z t_0))
(if (<= t_1 2e-76) (* t_0 (/ x z)) t_1))))
double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double t_1 = (x * t_0) / z;
double tmp;
if (t_1 <= -1e-55) {
tmp = x / (z / t_0);
} else if (t_1 <= 2e-76) {
tmp = t_0 * (x / z);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = sin(y) / y
t_1 = (x * t_0) / z
if (t_1 <= (-1d-55)) then
tmp = x / (z / t_0)
else if (t_1 <= 2d-76) then
tmp = t_0 * (x / z)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) / y;
double t_1 = (x * t_0) / z;
double tmp;
if (t_1 <= -1e-55) {
tmp = x / (z / t_0);
} else if (t_1 <= 2e-76) {
tmp = t_0 * (x / z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y t_1 = (x * t_0) / z tmp = 0 if t_1 <= -1e-55: tmp = x / (z / t_0) elif t_1 <= 2e-76: tmp = t_0 * (x / z) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(sin(y) / y) t_1 = Float64(Float64(x * t_0) / z) tmp = 0.0 if (t_1 <= -1e-55) tmp = Float64(x / Float64(z / t_0)); elseif (t_1 <= 2e-76) tmp = Float64(t_0 * Float64(x / z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; t_1 = (x * t_0) / z; tmp = 0.0; if (t_1 <= -1e-55) tmp = x / (z / t_0); elseif (t_1 <= 2e-76) tmp = t_0 * (x / z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-55], N[(x / N[(z / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-76], N[(t$95$0 * N[(x / z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
t_1 := \frac{x \cdot t_0}{z}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-55}:\\
\;\;\;\;\frac{x}{\frac{z}{t_0}}\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-76}:\\
\;\;\;\;t_0 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -9.99999999999999995e-56Initial program 99.8%
associate-/l*99.9%
Simplified99.9%
if -9.99999999999999995e-56 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < 1.99999999999999985e-76Initial program 93.5%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
if 1.99999999999999985e-76 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 99.7%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-31) (not (<= z 1.6e-53))) (* (/ (sin y) y) (/ x z)) (* x (/ (/ (sin y) z) y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-31) || !(z <= 1.6e-53)) {
tmp = (sin(y) / y) * (x / z);
} else {
tmp = x * ((sin(y) / z) / y);
}
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 <= (-3d-31)) .or. (.not. (z <= 1.6d-53))) then
tmp = (sin(y) / y) * (x / z)
else
tmp = x * ((sin(y) / z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-31) || !(z <= 1.6e-53)) {
tmp = (Math.sin(y) / y) * (x / z);
} else {
tmp = x * ((Math.sin(y) / z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-31) or not (z <= 1.6e-53): tmp = (math.sin(y) / y) * (x / z) else: tmp = x * ((math.sin(y) / z) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e-31) || !(z <= 1.6e-53)) tmp = Float64(Float64(sin(y) / y) * Float64(x / z)); else tmp = Float64(x * Float64(Float64(sin(y) / z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e-31) || ~((z <= 1.6e-53))) tmp = (sin(y) / y) * (x / z); else tmp = x * ((sin(y) / z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-31], N[Not[LessEqual[z, 1.6e-53]], $MachinePrecision]], N[(N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-31} \lor \neg \left(z \leq 1.6 \cdot 10^{-53}\right):\\
\;\;\;\;\frac{\sin y}{y} \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{\frac{\sin y}{z}}{y}\\
\end{array}
\end{array}
if z < -2.99999999999999981e-31 or 1.6e-53 < z Initial program 99.0%
associate-*l/99.8%
*-commutative99.8%
Simplified99.8%
if -2.99999999999999981e-31 < z < 1.6e-53Initial program 92.3%
associate-*r/99.6%
associate-/l/82.3%
associate-/r*99.6%
Simplified99.6%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (sin y) y))) (if (or (<= z -2e+83) (not (<= z 5e-35))) (* t_0 (/ x z)) (/ x (/ z t_0)))))
double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if ((z <= -2e+83) || !(z <= 5e-35)) {
tmp = t_0 * (x / z);
} else {
tmp = x / (z / 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 = sin(y) / y
if ((z <= (-2d+83)) .or. (.not. (z <= 5d-35))) then
tmp = t_0 * (x / z)
else
tmp = x / (z / t_0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) / y;
double tmp;
if ((z <= -2e+83) || !(z <= 5e-35)) {
tmp = t_0 * (x / z);
} else {
tmp = x / (z / t_0);
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y tmp = 0 if (z <= -2e+83) or not (z <= 5e-35): tmp = t_0 * (x / z) else: tmp = x / (z / t_0) return tmp
function code(x, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if ((z <= -2e+83) || !(z <= 5e-35)) tmp = Float64(t_0 * Float64(x / z)); else tmp = Float64(x / Float64(z / t_0)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; tmp = 0.0; if ((z <= -2e+83) || ~((z <= 5e-35))) tmp = t_0 * (x / z); else tmp = x / (z / t_0); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, If[Or[LessEqual[z, -2e+83], N[Not[LessEqual[z, 5e-35]], $MachinePrecision]], N[(t$95$0 * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathbf{if}\;z \leq -2 \cdot 10^{+83} \lor \neg \left(z \leq 5 \cdot 10^{-35}\right):\\
\;\;\;\;t_0 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{t_0}}\\
\end{array}
\end{array}
if z < -2.00000000000000006e83 or 4.99999999999999964e-35 < z Initial program 99.4%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
if -2.00000000000000006e83 < z < 4.99999999999999964e-35Initial program 93.6%
associate-/l*99.7%
Simplified99.7%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (* x (/ (/ (sin y) y) z)))
double code(double x, double y, double z) {
return x * ((sin(y) / 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 * ((sin(y) / y) / z)
end function
public static double code(double x, double y, double z) {
return x * ((Math.sin(y) / y) / z);
}
def code(x, y, z): return x * ((math.sin(y) / y) / z)
function code(x, y, z) return Float64(x * Float64(Float64(sin(y) / y) / z)) end
function tmp = code(x, y, z) tmp = x * ((sin(y) / y) / z); end
code[x_, y_, z_] := N[(x * N[(N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{\sin y}{y}}{z}
\end{array}
Initial program 96.4%
associate-*r/95.3%
Simplified95.3%
Final simplification95.3%
(FPCore (x y z) :precision binary64 (if (<= y 3.9e-12) (/ x z) (/ 1.0 (* (/ 1.0 y) (/ (* y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.9e-12) {
tmp = x / z;
} else {
tmp = 1.0 / ((1.0 / y) * ((y * z) / 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 (y <= 3.9d-12) then
tmp = x / z
else
tmp = 1.0d0 / ((1.0d0 / y) * ((y * z) / x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3.9e-12) {
tmp = x / z;
} else {
tmp = 1.0 / ((1.0 / y) * ((y * z) / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.9e-12: tmp = x / z else: tmp = 1.0 / ((1.0 / y) * ((y * z) / x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.9e-12) tmp = Float64(x / z); else tmp = Float64(1.0 / Float64(Float64(1.0 / y) * Float64(Float64(y * z) / x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.9e-12) tmp = x / z; else tmp = 1.0 / ((1.0 / y) * ((y * z) / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.9e-12], N[(x / z), $MachinePrecision], N[(1.0 / N[(N[(1.0 / y), $MachinePrecision] * N[(N[(y * z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.9 \cdot 10^{-12}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{y} \cdot \frac{y \cdot z}{x}}\\
\end{array}
\end{array}
if y < 3.89999999999999994e-12Initial program 97.7%
Taylor expanded in y around 0 65.7%
if 3.89999999999999994e-12 < y Initial program 92.2%
associate-*r/94.0%
associate-/l/93.5%
associate-/r*94.1%
Simplified94.1%
Taylor expanded in y around 0 21.8%
associate-*r/21.7%
clear-num22.7%
Applied egg-rr22.7%
associate-*r/22.8%
*-commutative22.8%
associate-/l*27.3%
*-un-lft-identity27.3%
times-frac37.4%
*-commutative37.4%
Applied egg-rr37.4%
Final simplification58.9%
(FPCore (x y z) :precision binary64 (if (<= y 2e+22) (/ x z) (/ y (/ (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2e+22) {
tmp = x / z;
} else {
tmp = y / ((y * z) / 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 (y <= 2d+22) then
tmp = x / z
else
tmp = y / ((y * z) / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2e+22) {
tmp = x / z;
} else {
tmp = y / ((y * z) / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2e+22: tmp = x / z else: tmp = y / ((y * z) / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2e+22) tmp = Float64(x / z); else tmp = Float64(y / Float64(Float64(y * z) / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2e+22) tmp = x / z; else tmp = y / ((y * z) / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2e+22], N[(x / z), $MachinePrecision], N[(y / N[(N[(y * z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{+22}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{y \cdot z}{x}}\\
\end{array}
\end{array}
if y < 2e22Initial program 97.7%
Taylor expanded in y around 0 64.7%
if 2e22 < y Initial program 91.1%
associate-*r/93.1%
Simplified93.1%
Taylor expanded in y around 0 19.2%
*-un-lft-identity19.2%
*-inverses19.2%
un-div-inv19.2%
times-frac25.2%
associate-/l*36.8%
*-commutative36.8%
Applied egg-rr36.8%
Final simplification58.9%
(FPCore (x y z) :precision binary64 (/ x z))
double code(double x, double y, double z) {
return x / 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
end function
public static double code(double x, double y, double z) {
return x / z;
}
def code(x, y, z): return x / z
function code(x, y, z) return Float64(x / z) end
function tmp = code(x, y, z) tmp = x / z; end
code[x_, y_, z_] := N[(x / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z}
\end{array}
Initial program 96.4%
Taylor expanded in y around 0 55.3%
Final simplification55.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (sin y))) (t_1 (/ (* x (/ 1.0 t_0)) z)))
(if (< z -4.2173720203427147e-29)
t_1
(if (< z 4.446702369113811e+64) (/ x (* z t_0)) t_1))))
double code(double x, double y, double z) {
double t_0 = y / sin(y);
double t_1 = (x * (1.0 / t_0)) / z;
double tmp;
if (z < -4.2173720203427147e-29) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x / (z * t_0);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = y / sin(y)
t_1 = (x * (1.0d0 / t_0)) / z
if (z < (-4.2173720203427147d-29)) then
tmp = t_1
else if (z < 4.446702369113811d+64) then
tmp = x / (z * t_0)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / Math.sin(y);
double t_1 = (x * (1.0 / t_0)) / z;
double tmp;
if (z < -4.2173720203427147e-29) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x / (z * t_0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y / math.sin(y) t_1 = (x * (1.0 / t_0)) / z tmp = 0 if z < -4.2173720203427147e-29: tmp = t_1 elif z < 4.446702369113811e+64: tmp = x / (z * t_0) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y / sin(y)) t_1 = Float64(Float64(x * Float64(1.0 / t_0)) / z) tmp = 0.0 if (z < -4.2173720203427147e-29) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = Float64(x / Float64(z * t_0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / sin(y); t_1 = (x * (1.0 / t_0)) / z; tmp = 0.0; if (z < -4.2173720203427147e-29) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = x / (z * t_0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Less[z, -4.2173720203427147e-29], t$95$1, If[Less[z, 4.446702369113811e+64], N[(x / N[(z * t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{\sin y}\\
t_1 := \frac{x \cdot \frac{1}{t_0}}{z}\\
\mathbf{if}\;z < -4.2173720203427147 \cdot 10^{-29}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z < 4.446702369113811 \cdot 10^{+64}:\\
\;\;\;\;\frac{x}{z \cdot t_0}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
herbie shell --seed 2023305
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< z -4.2173720203427147e-29) (/ (* x (/ 1.0 (/ y (sin y)))) z) (if (< z 4.446702369113811e+64) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1.0 (/ y (sin y)))) z)))
(/ (* x (/ (sin y) y)) z))