
(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))) (if (<= z -1e+25) (* 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 <= -1e+25) {
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 <= (-1d+25)) 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 <= -1e+25) {
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 <= -1e+25: 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 <= -1e+25) 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 <= -1e+25) 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[LessEqual[z, -1e+25], 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 -1 \cdot 10^{+25}:\\
\;\;\;\;t_0 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{t_0}}\\
\end{array}
\end{array}
if z < -1.00000000000000009e25Initial program 99.8%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
if -1.00000000000000009e25 < z Initial program 96.2%
associate-/l*98.3%
Simplified98.3%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (sin y) y))) (if (<= z -2e-58) (* t_0 (/ x z)) (* x (/ t_0 z)))))
double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if (z <= -2e-58) {
tmp = t_0 * (x / z);
} else {
tmp = x * (t_0 / z);
}
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-58)) then
tmp = t_0 * (x / z)
else
tmp = x * (t_0 / z)
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-58) {
tmp = t_0 * (x / z);
} else {
tmp = x * (t_0 / z);
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y tmp = 0 if z <= -2e-58: tmp = t_0 * (x / z) else: tmp = x * (t_0 / z) return tmp
function code(x, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (z <= -2e-58) tmp = Float64(t_0 * Float64(x / z)); else tmp = Float64(x * Float64(t_0 / z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; tmp = 0.0; if (z <= -2e-58) tmp = t_0 * (x / z); else tmp = x * (t_0 / z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[z, -2e-58], N[(t$95$0 * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(t$95$0 / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathbf{if}\;z \leq -2 \cdot 10^{-58}:\\
\;\;\;\;t_0 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{t_0}{z}\\
\end{array}
\end{array}
if z < -2.0000000000000001e-58Initial program 99.0%
associate-*l/99.8%
*-commutative99.8%
Simplified99.8%
if -2.0000000000000001e-58 < z Initial program 96.0%
associate-*r/98.0%
Simplified98.0%
Final simplification98.6%
(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 97.0%
associate-*r/95.3%
Simplified95.3%
Final simplification95.3%
(FPCore (x y z) :precision binary64 (if (<= y 1.9e-10) (/ x z) (* y (/ x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-10) {
tmp = x / z;
} else {
tmp = y * (x / (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 (y <= 1.9d-10) then
tmp = x / z
else
tmp = y * (x / (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-10) {
tmp = x / z;
} else {
tmp = y * (x / (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.9e-10: tmp = x / z else: tmp = y * (x / (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.9e-10) tmp = Float64(x / z); else tmp = Float64(y * Float64(x / Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.9e-10) tmp = x / z; else tmp = y * (x / (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.9e-10], N[(x / z), $MachinePrecision], N[(y * N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-10}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z \cdot y}\\
\end{array}
\end{array}
if y < 1.8999999999999999e-10Initial program 97.6%
Taylor expanded in y around 0 71.8%
if 1.8999999999999999e-10 < y Initial program 94.7%
associate-*r/93.2%
Simplified93.2%
Taylor expanded in y around 0 21.8%
div-inv21.8%
clear-num21.8%
Applied egg-rr21.8%
associate-/l*21.8%
associate-*r/21.8%
*-inverses21.8%
times-frac31.2%
*-un-lft-identity31.2%
times-frac34.8%
/-rgt-identity34.8%
Applied egg-rr34.8%
Final simplification63.4%
(FPCore (x y z) :precision binary64 (if (<= y 3.35e-15) (/ x z) (/ y (* z (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.35e-15) {
tmp = x / z;
} else {
tmp = y / (z * (y / 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.35d-15) then
tmp = x / z
else
tmp = y / (z * (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3.35e-15) {
tmp = x / z;
} else {
tmp = y / (z * (y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.35e-15: tmp = x / z else: tmp = y / (z * (y / x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.35e-15) tmp = Float64(x / z); else tmp = Float64(y / Float64(z * Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.35e-15) tmp = x / z; else tmp = y / (z * (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.35e-15], N[(x / z), $MachinePrecision], N[(y / N[(z * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.35 \cdot 10^{-15}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z \cdot \frac{y}{x}}\\
\end{array}
\end{array}
if y < 3.35e-15Initial program 97.6%
Taylor expanded in y around 0 71.8%
if 3.35e-15 < y Initial program 94.7%
associate-*r/93.2%
associate-/l/93.2%
associate-/r*93.3%
Simplified93.3%
Taylor expanded in y around 0 21.7%
div-inv21.7%
div-inv21.7%
associate-*l*33.2%
Applied egg-rr33.2%
*-commutative33.2%
un-div-inv33.2%
associate-/l/33.2%
un-div-inv33.2%
associate-/r/35.6%
*-commutative35.6%
*-un-lft-identity35.6%
times-frac35.4%
/-rgt-identity35.4%
Applied egg-rr35.4%
Final simplification63.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.9e-10) (/ x z) (/ y (/ (* z y) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-10) {
tmp = x / z;
} else {
tmp = y / ((z * y) / 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 <= 1.9d-10) then
tmp = x / z
else
tmp = y / ((z * y) / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-10) {
tmp = x / z;
} else {
tmp = y / ((z * y) / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.9e-10: tmp = x / z else: tmp = y / ((z * y) / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.9e-10) tmp = Float64(x / z); else tmp = Float64(y / Float64(Float64(z * y) / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.9e-10) tmp = x / z; else tmp = y / ((z * y) / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.9e-10], N[(x / z), $MachinePrecision], N[(y / N[(N[(z * y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-10}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z \cdot y}{x}}\\
\end{array}
\end{array}
if y < 1.8999999999999999e-10Initial program 97.6%
Taylor expanded in y around 0 71.8%
if 1.8999999999999999e-10 < y Initial program 94.7%
associate-*r/93.2%
associate-/l/93.2%
associate-/r*93.3%
Simplified93.3%
Taylor expanded in y around 0 21.7%
div-inv21.7%
div-inv21.7%
associate-*l*33.2%
Applied egg-rr33.2%
*-commutative33.2%
un-div-inv33.2%
associate-/l/33.2%
un-div-inv33.2%
associate-/r/35.6%
*-commutative35.6%
*-un-lft-identity35.6%
times-frac35.4%
/-rgt-identity35.4%
Applied egg-rr35.4%
Taylor expanded in z around 0 35.6%
Final simplification63.6%
(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 97.0%
Taylor expanded in y around 0 60.5%
Final simplification60.5%
(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 2023310
(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))