
(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 9 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 -2e-317) t_1 (/ x (/ z t_0)))))
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 <= -2e-317) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = sin(y) / y
t_1 = (x * t_0) / z
if (t_1 <= (-2d-317)) then
tmp = t_1
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 t_1 = (x * t_0) / z;
double tmp;
if (t_1 <= -2e-317) {
tmp = t_1;
} else {
tmp = x / (z / t_0);
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y t_1 = (x * t_0) / z tmp = 0 if t_1 <= -2e-317: tmp = t_1 else: tmp = x / (z / t_0) 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 <= -2e-317) tmp = t_1; else tmp = Float64(x / Float64(z / t_0)); 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 <= -2e-317) tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-317], t$95$1, N[(x / N[(z / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\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 -2 \cdot 10^{-317}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{t_0}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -1.99999997e-317Initial program 99.7%
if -1.99999997e-317 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 88.9%
associate-/l*99.9%
Simplified99.9%
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 92.8%
associate-*r/98.1%
Simplified98.1%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (/ x (/ z (/ (sin y) y))))
double code(double x, double y, double z) {
return x / (z / (sin(y) / 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 / (sin(y) / y))
end function
public static double code(double x, double y, double z) {
return x / (z / (Math.sin(y) / y));
}
def code(x, y, z): return x / (z / (math.sin(y) / y))
function code(x, y, z) return Float64(x / Float64(z / Float64(sin(y) / y))) end
function tmp = code(x, y, z) tmp = x / (z / (sin(y) / y)); end
code[x_, y_, z_] := N[(x / N[(z / N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{\frac{\sin y}{y}}}
\end{array}
Initial program 92.8%
associate-/l*98.2%
Simplified98.2%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= y 1.9e-32) (/ x z) (* x (/ y (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-32) {
tmp = x / z;
} else {
tmp = x * (y / (y * 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) :: tmp
if (y <= 1.9d-32) then
tmp = x / z
else
tmp = x * (y / (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-32) {
tmp = x / z;
} else {
tmp = x * (y / (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.9e-32: tmp = x / z else: tmp = x * (y / (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.9e-32) tmp = Float64(x / z); else tmp = Float64(x * Float64(y / Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.9e-32) tmp = x / z; else tmp = x * (y / (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.9e-32], N[(x / z), $MachinePrecision], N[(x * N[(y / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-32}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{y \cdot z}\\
\end{array}
\end{array}
if y < 1.90000000000000004e-32Initial program 93.4%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 72.8%
if 1.90000000000000004e-32 < y Initial program 90.8%
associate-*r/93.3%
associate-/l/93.2%
associate-/r*93.2%
Simplified93.2%
Taylor expanded in y around 0 21.1%
div-inv21.1%
Applied egg-rr21.1%
un-div-inv21.1%
associate-/l/29.0%
Applied egg-rr29.0%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (if (<= y 0.4) (/ x z) (* y (/ x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 0.4) {
tmp = x / z;
} else {
tmp = y * (x / (y * 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) :: tmp
if (y <= 0.4d0) then
tmp = x / z
else
tmp = y * (x / (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 0.4) {
tmp = x / z;
} else {
tmp = y * (x / (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 0.4: tmp = x / z else: tmp = y * (x / (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 0.4) tmp = Float64(x / z); else tmp = Float64(y * Float64(x / Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 0.4) tmp = x / z; else tmp = y * (x / (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 0.4], N[(x / z), $MachinePrecision], N[(y * N[(x / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.4:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y \cdot z}\\
\end{array}
\end{array}
if y < 0.40000000000000002Initial program 93.6%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 73.5%
if 0.40000000000000002 < y Initial program 90.1%
associate-*r/92.7%
Simplified92.7%
Taylor expanded in y around 0 14.8%
div-inv14.8%
clear-num15.5%
Applied egg-rr15.5%
*-un-lft-identity15.5%
rgt-mult-inverse15.5%
un-div-inv15.5%
clear-num14.8%
times-frac21.4%
*-commutative21.4%
*-un-lft-identity21.4%
times-frac32.6%
/-rgt-identity32.6%
*-commutative32.6%
Applied egg-rr32.6%
Final simplification64.1%
(FPCore (x y z) :precision binary64 (if (<= y 5.7e-5) (/ x z) (/ y (* z (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 5.7e-5) {
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 <= 5.7d-5) 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 <= 5.7e-5) {
tmp = x / z;
} else {
tmp = y / (z * (y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 5.7e-5: tmp = x / z else: tmp = y / (z * (y / x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 5.7e-5) 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 <= 5.7e-5) tmp = x / z; else tmp = y / (z * (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 5.7e-5], N[(x / z), $MachinePrecision], N[(y / N[(z * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.7 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z \cdot \frac{y}{x}}\\
\end{array}
\end{array}
if y < 5.7000000000000003e-5Initial program 93.6%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 73.5%
if 5.7000000000000003e-5 < y Initial program 90.1%
associate-*r/92.7%
associate-/l/92.6%
associate-/r*92.6%
Simplified92.6%
Taylor expanded in y around 0 14.4%
div-inv14.4%
Applied egg-rr14.4%
un-div-inv14.4%
associate-/l/22.9%
Applied egg-rr22.9%
associate-*r/21.4%
frac-times17.9%
clear-num19.4%
frac-times32.7%
*-un-lft-identity32.7%
Applied egg-rr32.7%
Final simplification64.1%
(FPCore (x y z) :precision binary64 (if (<= y 1.15e-5) (/ x z) (/ y (/ z (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.15e-5) {
tmp = x / z;
} else {
tmp = y / (z / (x / 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.15d-5) then
tmp = x / z
else
tmp = y / (z / (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.15e-5) {
tmp = x / z;
} else {
tmp = y / (z / (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.15e-5: tmp = x / z else: tmp = y / (z / (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.15e-5) tmp = Float64(x / z); else tmp = Float64(y / Float64(z / Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.15e-5) tmp = x / z; else tmp = y / (z / (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.15e-5], N[(x / z), $MachinePrecision], N[(y / N[(z / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.15 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{\frac{x}{y}}}\\
\end{array}
\end{array}
if y < 1.15e-5Initial program 93.6%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 73.5%
if 1.15e-5 < y Initial program 90.1%
associate-*r/92.7%
Simplified92.7%
associate-*r/90.1%
associate-*l/91.7%
clear-num91.7%
frac-times91.1%
*-un-lft-identity91.1%
Applied egg-rr91.1%
Taylor expanded in y around 0 32.3%
Taylor expanded in z around 0 32.6%
*-commutative32.6%
associate-/l*32.7%
Simplified32.7%
Final simplification64.1%
(FPCore (x y z) :precision binary64 (/ 1.0 (/ z x)))
double code(double x, double y, double z) {
return 1.0 / (z / x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 / (z / x)
end function
public static double code(double x, double y, double z) {
return 1.0 / (z / x);
}
def code(x, y, z): return 1.0 / (z / x)
function code(x, y, z) return Float64(1.0 / Float64(z / x)) end
function tmp = code(x, y, z) tmp = 1.0 / (z / x); end
code[x_, y_, z_] := N[(1.0 / N[(z / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{z}{x}}
\end{array}
Initial program 92.8%
associate-*r/98.1%
Simplified98.1%
Taylor expanded in y around 0 59.8%
div-inv60.0%
clear-num60.1%
Applied egg-rr60.1%
Final simplification60.1%
(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 92.8%
associate-/l*98.2%
Simplified98.2%
Taylor expanded in y around 0 60.0%
Final simplification60.0%
(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 2023308
(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))