
(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 (/ 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 95.4%
clear-numN/A
un-div-invN/A
associate-/l/N/A
/-lowering-/.f64N/A
clear-numN/A
div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6498.4%
Applied egg-rr98.4%
(FPCore (x y z) :precision binary64 (if (<= y 0.00019) (* (/ x z) (+ (* y (* y -0.16666666666666666)) 1.0)) (* (sin y) (/ x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 0.00019) {
tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0);
} else {
tmp = sin(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 <= 0.00019d0) then
tmp = (x / z) * ((y * (y * (-0.16666666666666666d0))) + 1.0d0)
else
tmp = sin(y) * (x / (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 0.00019) {
tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0);
} else {
tmp = Math.sin(y) * (x / (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 0.00019: tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0) else: tmp = math.sin(y) * (x / (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 0.00019) tmp = Float64(Float64(x / z) * Float64(Float64(y * Float64(y * -0.16666666666666666)) + 1.0)); else tmp = Float64(sin(y) * Float64(x / Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 0.00019) tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0); else tmp = sin(y) * (x / (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 0.00019], N[(N[(x / z), $MachinePrecision] * N[(N[(y * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.00019:\\
\;\;\;\;\frac{x}{z} \cdot \left(y \cdot \left(y \cdot -0.16666666666666666\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{x}{z \cdot y}\\
\end{array}
\end{array}
if y < 1.9000000000000001e-4Initial program 96.7%
/-lowering-/.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6486.5%
Simplified86.5%
Taylor expanded in y around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6460.8%
Simplified60.8%
associate-/l/N/A
times-fracN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6472.0%
Applied egg-rr72.0%
*-inversesN/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6472.0%
Applied egg-rr72.0%
if 1.9000000000000001e-4 < y Initial program 92.1%
associate-*r/N/A
associate-/l/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
sin-lowering-sin.f6497.0%
Applied egg-rr97.0%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (<= y 1.15e+30) (* (/ x z) (+ (* y (* y -0.16666666666666666)) 1.0)) (* y (/ x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.15e+30) {
tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0);
} 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.15d+30) then
tmp = (x / z) * ((y * (y * (-0.16666666666666666d0))) + 1.0d0)
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.15e+30) {
tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0);
} else {
tmp = y * (x / (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.15e+30: tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0) else: tmp = y * (x / (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.15e+30) tmp = Float64(Float64(x / z) * Float64(Float64(y * Float64(y * -0.16666666666666666)) + 1.0)); 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.15e+30) tmp = (x / z) * ((y * (y * -0.16666666666666666)) + 1.0); else tmp = y * (x / (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.15e+30], N[(N[(x / z), $MachinePrecision] * N[(N[(y * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.15 \cdot 10^{+30}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y \cdot \left(y \cdot -0.16666666666666666\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z \cdot y}\\
\end{array}
\end{array}
if y < 1.15e30Initial program 96.9%
/-lowering-/.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6487.4%
Simplified87.4%
Taylor expanded in y around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6457.8%
Simplified57.8%
associate-/l/N/A
times-fracN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6468.2%
Applied egg-rr68.2%
*-inversesN/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6468.2%
Applied egg-rr68.2%
if 1.15e30 < y Initial program 90.2%
associate-*r/N/A
associate-/l/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
sin-lowering-sin.f6496.5%
Applied egg-rr96.5%
Taylor expanded in y around 0
Simplified26.8%
Final simplification58.8%
(FPCore (x y z) :precision binary64 (/ 1.0 (* (+ 1.0 (* (* y y) 0.16666666666666666)) (/ z x))))
double code(double x, double y, double z) {
return 1.0 / ((1.0 + ((y * y) * 0.16666666666666666)) * (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 / ((1.0d0 + ((y * y) * 0.16666666666666666d0)) * (z / x))
end function
public static double code(double x, double y, double z) {
return 1.0 / ((1.0 + ((y * y) * 0.16666666666666666)) * (z / x));
}
def code(x, y, z): return 1.0 / ((1.0 + ((y * y) * 0.16666666666666666)) * (z / x))
function code(x, y, z) return Float64(1.0 / Float64(Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666)) * Float64(z / x))) end
function tmp = code(x, y, z) tmp = 1.0 / ((1.0 + ((y * y) * 0.16666666666666666)) * (z / x)); end
code[x_, y_, z_] := N[(1.0 / N[(N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(1 + \left(y \cdot y\right) \cdot 0.16666666666666666\right) \cdot \frac{z}{x}}
\end{array}
Initial program 95.4%
/-lowering-/.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6488.0%
Simplified88.0%
Taylor expanded in y around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6445.2%
Simplified45.2%
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
associate-/l/N/A
clear-numN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6439.7%
Applied egg-rr39.7%
Taylor expanded in y around 0
associate-/l*N/A
associate-*r*N/A
distribute-lft1-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6467.6%
Simplified67.6%
Final simplification67.6%
(FPCore (x y z) :precision binary64 (if (<= y 0.00095) (/ x z) (* y (/ x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 0.00095) {
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 <= 0.00095d0) 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 <= 0.00095) {
tmp = x / z;
} else {
tmp = y * (x / (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 0.00095: tmp = x / z else: tmp = y * (x / (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 0.00095) 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 <= 0.00095) tmp = x / z; else tmp = y * (x / (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 0.00095], N[(x / z), $MachinePrecision], N[(y * N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.00095:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z \cdot y}\\
\end{array}
\end{array}
if y < 9.49999999999999998e-4Initial program 96.7%
Taylor expanded in y around 0
/-lowering-/.f6476.7%
Simplified76.7%
if 9.49999999999999998e-4 < y Initial program 92.1%
associate-*r/N/A
associate-/l/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
sin-lowering-sin.f6497.0%
Applied egg-rr97.0%
Taylor expanded in y around 0
Simplified24.0%
Final simplification61.9%
(FPCore (x y z) :precision binary64 (/ x (* z (+ 1.0 (* (* y y) 0.16666666666666666)))))
double code(double x, double y, double z) {
return x / (z * (1.0 + ((y * y) * 0.16666666666666666)));
}
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 + ((y * y) * 0.16666666666666666d0)))
end function
public static double code(double x, double y, double z) {
return x / (z * (1.0 + ((y * y) * 0.16666666666666666)));
}
def code(x, y, z): return x / (z * (1.0 + ((y * y) * 0.16666666666666666)))
function code(x, y, z) return Float64(x / Float64(z * Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666)))) end
function tmp = code(x, y, z) tmp = x / (z * (1.0 + ((y * y) * 0.16666666666666666))); end
code[x_, y_, z_] := N[(x / N[(z * N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z \cdot \left(1 + \left(y \cdot y\right) \cdot 0.16666666666666666\right)}
\end{array}
Initial program 95.4%
clear-numN/A
un-div-invN/A
associate-/l/N/A
/-lowering-/.f64N/A
clear-numN/A
div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6498.4%
Applied egg-rr98.4%
Taylor expanded in y around 0
associate-*r*N/A
distribute-rgt1-inN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6467.4%
Simplified67.4%
Final simplification67.4%
(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 95.4%
Taylor expanded in y around 0
/-lowering-/.f6459.6%
Simplified59.6%
(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 2024158
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
:alt
(! :herbie-platform default (if (< z -42173720203427147/1000000000000000000000000000000000000000000000) (/ (* x (/ 1 (/ y (sin y)))) z) (if (< z 44467023691138110000000000000000000000000000000000000000000000000) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1 (/ y (sin y)))) z))))
(/ (* x (/ (sin y) y)) z))