
(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 4 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}
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= y 1.2e-8) (/ x z) (* (sin y) (/ x (* z y)))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (y <= 1.2e-8) {
tmp = x / z;
} else {
tmp = sin(y) * (x / (z * y));
}
return tmp;
}
NOTE: y should be positive before calling this function
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 <= 1.2d-8) then
tmp = x / z
else
tmp = sin(y) * (x / (z * y))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.2e-8) {
tmp = x / z;
} else {
tmp = Math.sin(y) * (x / (z * y));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if y <= 1.2e-8: tmp = x / z else: tmp = math.sin(y) * (x / (z * y)) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if (y <= 1.2e-8) tmp = Float64(x / z); else tmp = Float64(sin(y) * Float64(x / Float64(z * y))); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.2e-8) tmp = x / z; else tmp = sin(y) * (x / (z * y)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[y, 1.2e-8], N[(x / z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{x}{z \cdot y}\\
\end{array}
\end{array}
if y < 1.19999999999999999e-8Initial program 99.9%
associate-*l/100.0%
times-frac61.4%
*-commutative61.4%
associate-*r/65.3%
*-commutative65.3%
Simplified65.3%
Taylor expanded in y around 0 97.7%
if 1.19999999999999999e-8 < y Initial program 99.6%
associate-*l/92.5%
times-frac99.6%
*-commutative99.6%
associate-*r/99.6%
*-commutative99.6%
Simplified99.6%
Final simplification97.8%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x (/ z (/ (sin y) y))))
y = abs(y);
double code(double x, double y, double z) {
return x / (z / (sin(y) / y));
}
NOTE: y should be positive before calling this function
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 / (sin(y) / y))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / (z / (Math.sin(y) / y));
}
y = abs(y) def code(x, y, z): return x / (z / (math.sin(y) / y))
y = abs(y) function code(x, y, z) return Float64(x / Float64(z / Float64(sin(y) / y))) end
y = abs(y) function tmp = code(x, y, z) tmp = x / (z / (sin(y) / y)); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / N[(z / N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{\frac{z}{\frac{\sin y}{y}}}
\end{array}
Initial program 99.9%
associate-/l*100.0%
Simplified100.0%
Final simplification100.0%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x (/ z (+ 1.0 (* -0.16666666666666666 (* y y))))))
y = abs(y);
double code(double x, double y, double z) {
return x / (z / (1.0 + (-0.16666666666666666 * (y * y))));
}
NOTE: y should be positive before calling this function
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 / (1.0d0 + ((-0.16666666666666666d0) * (y * y))))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / (z / (1.0 + (-0.16666666666666666 * (y * y))));
}
y = abs(y) def code(x, y, z): return x / (z / (1.0 + (-0.16666666666666666 * (y * y))))
y = abs(y) function code(x, y, z) return Float64(x / Float64(z / Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y))))) end
y = abs(y) function tmp = code(x, y, z) tmp = x / (z / (1.0 + (-0.16666666666666666 * (y * y)))); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / N[(z / N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{\frac{z}{1 + -0.16666666666666666 \cdot \left(y \cdot y\right)}}
\end{array}
Initial program 99.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 97.5%
unpow297.5%
Simplified97.5%
Final simplification97.5%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x z))
y = abs(y);
double code(double x, double y, double z) {
return x / z;
}
NOTE: y should be positive before calling this function
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
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / z;
}
y = abs(y) def code(x, y, z): return x / z
y = abs(y) function code(x, y, z) return Float64(x / z) end
y = abs(y) function tmp = code(x, y, z) tmp = x / z; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / z), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{z}
\end{array}
Initial program 99.9%
associate-*l/99.6%
times-frac63.2%
*-commutative63.2%
associate-*r/67.0%
*-commutative67.0%
Simplified67.0%
Taylor expanded in y around 0 95.4%
Final simplification95.4%
(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 2023278
(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))