
(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 8 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))) (if (<= t_1 -5e-297) (/ t_1 z) (/ x (/ z t_0)))))
double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double t_1 = x * t_0;
double tmp;
if (t_1 <= -5e-297) {
tmp = t_1 / 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) :: t_1
real(8) :: tmp
t_0 = sin(y) / y
t_1 = x * t_0
if (t_1 <= (-5d-297)) then
tmp = t_1 / 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 t_1 = x * t_0;
double tmp;
if (t_1 <= -5e-297) {
tmp = t_1 / z;
} else {
tmp = x / (z / t_0);
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y t_1 = x * t_0 tmp = 0 if t_1 <= -5e-297: tmp = t_1 / z else: tmp = x / (z / t_0) return tmp
function code(x, y, z) t_0 = Float64(sin(y) / y) t_1 = Float64(x * t_0) tmp = 0.0 if (t_1 <= -5e-297) tmp = Float64(t_1 / 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; t_1 = x * t_0; tmp = 0.0; if (t_1 <= -5e-297) tmp = t_1 / 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]}, Block[{t$95$1 = N[(x * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e-297], N[(t$95$1 / z), $MachinePrecision], N[(x / N[(z / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
t_1 := x \cdot t_0\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{-297}:\\
\;\;\;\;\frac{t_1}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{t_0}}\\
\end{array}
\end{array}
if (*.f64 x (/.f64 (sin.f64 y) y)) < -5e-297Initial program 99.8%
if -5e-297 < (*.f64 x (/.f64 (sin.f64 y) y)) Initial program 92.6%
associate-/l*97.8%
Simplified97.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y 7.6e-26) (/ x z) (* (sin y) (/ x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 7.6e-26) {
tmp = x / z;
} else {
tmp = sin(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 <= 7.6d-26) then
tmp = x / z
else
tmp = sin(y) * (x / (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 7.6e-26) {
tmp = x / z;
} else {
tmp = Math.sin(y) * (x / (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 7.6e-26: tmp = x / z else: tmp = math.sin(y) * (x / (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 7.6e-26) tmp = Float64(x / z); else tmp = Float64(sin(y) * Float64(x / Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 7.6e-26) tmp = x / z; else tmp = sin(y) * (x / (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 7.6e-26], N[(x / z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(x / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.6 \cdot 10^{-26}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{x}{y \cdot z}\\
\end{array}
\end{array}
if y < 7.60000000000000029e-26Initial program 95.4%
associate-*l/97.8%
times-frac82.3%
*-commutative82.3%
associate-*r/81.8%
*-commutative81.8%
Simplified81.8%
Taylor expanded in y around 0 68.8%
if 7.60000000000000029e-26 < y Initial program 96.3%
associate-*l/94.8%
times-frac97.1%
*-commutative97.1%
associate-*r/97.1%
*-commutative97.1%
Simplified97.1%
Final simplification77.3%
(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.6%
associate-/l*96.1%
Simplified96.1%
Final simplification96.1%
(FPCore (x y z) :precision binary64 (if (<= y 135000000000.0) (/ x z) (* (/ (/ x y) z) (- y))))
double code(double x, double y, double z) {
double tmp;
if (y <= 135000000000.0) {
tmp = x / z;
} else {
tmp = ((x / 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 (y <= 135000000000.0d0) then
tmp = x / z
else
tmp = ((x / y) / z) * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 135000000000.0) {
tmp = x / z;
} else {
tmp = ((x / y) / z) * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 135000000000.0: tmp = x / z else: tmp = ((x / y) / z) * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 135000000000.0) tmp = Float64(x / z); else tmp = Float64(Float64(Float64(x / y) / z) * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 135000000000.0) tmp = x / z; else tmp = ((x / y) / z) * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 135000000000.0], N[(x / z), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] / z), $MachinePrecision] * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 135000000000:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y}}{z} \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 1.35e11Initial program 95.5%
associate-*l/97.9%
times-frac83.0%
*-commutative83.0%
associate-*r/82.5%
*-commutative82.5%
Simplified82.5%
Taylor expanded in y around 0 69.0%
if 1.35e11 < y Initial program 95.9%
associate-*r/95.7%
associate-/l/96.9%
*-commutative96.9%
times-frac95.8%
Simplified95.8%
Taylor expanded in y around 0 21.2%
frac-times18.5%
associate-/l*32.3%
Applied egg-rr32.3%
associate-/l*32.3%
associate-/r/21.2%
*-commutative21.2%
clear-num21.2%
div-inv21.2%
frac-2neg21.2%
associate-/r/32.3%
Applied egg-rr32.3%
add-sqr-sqrt16.8%
sqrt-unprod33.3%
sqr-neg33.3%
sqrt-unprod18.2%
add-sqr-sqrt35.3%
associate-/r*35.3%
expm1-log1p-u32.2%
expm1-udef32.5%
associate-/r*32.5%
Applied egg-rr32.5%
expm1-def32.2%
expm1-log1p35.3%
Simplified35.3%
Final simplification59.8%
(FPCore (x y z) :precision binary64 (if (<= y 2e+49) (/ x z) (* y (/ x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2e+49) {
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 <= 2d+49) 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 <= 2e+49) {
tmp = x / z;
} else {
tmp = y * (x / (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2e+49: tmp = x / z else: tmp = y * (x / (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2e+49) 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 <= 2e+49) tmp = x / z; else tmp = y * (x / (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2e+49], N[(x / z), $MachinePrecision], N[(y * N[(x / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{+49}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y \cdot z}\\
\end{array}
\end{array}
if y < 1.99999999999999989e49Initial program 95.7%
associate-*l/98.0%
times-frac83.8%
*-commutative83.8%
associate-*r/83.4%
*-commutative83.4%
Simplified83.4%
Taylor expanded in y around 0 65.6%
if 1.99999999999999989e49 < y Initial program 95.3%
associate-*r/95.1%
associate-/l/96.5%
*-commutative96.5%
times-frac95.2%
Simplified95.2%
Taylor expanded in y around 0 24.3%
frac-times21.1%
associate-/l*37.2%
Applied egg-rr37.2%
clear-num37.2%
associate-/r/37.2%
clear-num37.2%
*-commutative37.2%
Applied egg-rr37.2%
Final simplification59.0%
(FPCore (x y z) :precision binary64 (if (<= y 2.8e-11) (/ x z) (* y (/ (/ x y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.8e-11) {
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 <= 2.8d-11) 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 <= 2.8e-11) {
tmp = x / z;
} else {
tmp = y * ((x / y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.8e-11: tmp = x / z else: tmp = y * ((x / y) / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.8e-11) tmp = Float64(x / z); else tmp = Float64(y * Float64(Float64(x / y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.8e-11) tmp = x / z; else tmp = y * ((x / y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.8e-11], N[(x / z), $MachinePrecision], N[(y * N[(N[(x / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-11}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{\frac{x}{y}}{z}\\
\end{array}
\end{array}
if y < 2.8e-11Initial program 95.4%
associate-*l/97.9%
times-frac82.6%
*-commutative82.6%
associate-*r/82.1%
*-commutative82.1%
Simplified82.1%
Taylor expanded in y around 0 69.3%
if 2.8e-11 < y Initial program 96.1%
associate-*r/95.9%
associate-/l/97.0%
*-commutative97.0%
times-frac96.0%
Simplified96.0%
Taylor expanded in y around 0 23.1%
frac-times20.4%
associate-/l*33.6%
Applied egg-rr33.6%
associate-/l*33.6%
associate-/r/33.5%
Applied egg-rr33.5%
div-inv33.5%
associate-*l/33.6%
*-commutative33.6%
clear-num33.6%
*-commutative33.6%
associate-/r*33.6%
Applied egg-rr33.6%
Final simplification59.0%
(FPCore (x y z) :precision binary64 (if (<= y 0.5) (/ x z) (/ y (* z (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 0.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 <= 0.5d0) 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 <= 0.5) {
tmp = x / z;
} else {
tmp = y / (z * (y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 0.5: tmp = x / z else: tmp = y / (z * (y / x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 0.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 <= 0.5) tmp = x / z; else tmp = y / (z * (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 0.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 0.5:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z \cdot \frac{y}{x}}\\
\end{array}
\end{array}
if y < 0.5Initial program 95.5%
associate-*l/97.9%
times-frac82.7%
*-commutative82.7%
associate-*r/82.2%
*-commutative82.2%
Simplified82.2%
Taylor expanded in y around 0 69.5%
if 0.5 < y Initial program 96.1%
associate-*r/95.8%
associate-/l/97.0%
*-commutative97.0%
times-frac96.0%
Simplified96.0%
Taylor expanded in y around 0 22.0%
*-commutative22.0%
clear-num23.3%
frac-times32.7%
*-un-lft-identity32.7%
Applied egg-rr32.7%
Final simplification59.0%
(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.6%
associate-*l/96.9%
times-frac86.8%
*-commutative86.8%
associate-*r/86.4%
*-commutative86.4%
Simplified86.4%
Taylor expanded in y around 0 54.5%
Final simplification54.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 2023199
(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))