
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (* y 2.0)))) (/ (tan t_0) (sin t_0))))
double code(double x, double y) {
double t_0 = x / (y * 2.0);
return tan(t_0) / sin(t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = x / (y * 2.0d0)
code = tan(t_0) / sin(t_0)
end function
public static double code(double x, double y) {
double t_0 = x / (y * 2.0);
return Math.tan(t_0) / Math.sin(t_0);
}
def code(x, y): t_0 = x / (y * 2.0) return math.tan(t_0) / math.sin(t_0)
function code(x, y) t_0 = Float64(x / Float64(y * 2.0)) return Float64(tan(t_0) / sin(t_0)) end
function tmp = code(x, y) t_0 = x / (y * 2.0); tmp = tan(t_0) / sin(t_0); end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Tan[t$95$0], $MachinePrecision] / N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\frac{\tan t_0}{\sin t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (* y 2.0)))) (/ (tan t_0) (sin t_0))))
double code(double x, double y) {
double t_0 = x / (y * 2.0);
return tan(t_0) / sin(t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = x / (y * 2.0d0)
code = tan(t_0) / sin(t_0)
end function
public static double code(double x, double y) {
double t_0 = x / (y * 2.0);
return Math.tan(t_0) / Math.sin(t_0);
}
def code(x, y): t_0 = x / (y * 2.0) return math.tan(t_0) / math.sin(t_0)
function code(x, y) t_0 = Float64(x / Float64(y * 2.0)) return Float64(tan(t_0) / sin(t_0)) end
function tmp = code(x, y) t_0 = x / (y * 2.0); tmp = tan(t_0) / sin(t_0); end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Tan[t$95$0], $MachinePrecision] / N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\frac{\tan t_0}{\sin t_0}
\end{array}
\end{array}
NOTE: x should be positive before calling this function NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (let* ((t_0 (sqrt (/ 0.5 y)))) (if (<= (/ x (* y 2.0)) 5e+244) (/ 1.0 (cos (* t_0 (* x t_0)))) 1.0)))
x = abs(x);
y = abs(y);
double code(double x, double y) {
double t_0 = sqrt((0.5 / y));
double tmp;
if ((x / (y * 2.0)) <= 5e+244) {
tmp = 1.0 / cos((t_0 * (x * t_0)));
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((0.5d0 / y))
if ((x / (y * 2.0d0)) <= 5d+244) then
tmp = 1.0d0 / cos((t_0 * (x * t_0)))
else
tmp = 1.0d0
end if
code = tmp
end function
x = Math.abs(x);
y = Math.abs(y);
public static double code(double x, double y) {
double t_0 = Math.sqrt((0.5 / y));
double tmp;
if ((x / (y * 2.0)) <= 5e+244) {
tmp = 1.0 / Math.cos((t_0 * (x * t_0)));
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) y = abs(y) def code(x, y): t_0 = math.sqrt((0.5 / y)) tmp = 0 if (x / (y * 2.0)) <= 5e+244: tmp = 1.0 / math.cos((t_0 * (x * t_0))) else: tmp = 1.0 return tmp
x = abs(x) y = abs(y) function code(x, y) t_0 = sqrt(Float64(0.5 / y)) tmp = 0.0 if (Float64(x / Float64(y * 2.0)) <= 5e+244) tmp = Float64(1.0 / cos(Float64(t_0 * Float64(x * t_0)))); else tmp = 1.0; end return tmp end
x = abs(x) y = abs(y) function tmp_2 = code(x, y) t_0 = sqrt((0.5 / y)); tmp = 0.0; if ((x / (y * 2.0)) <= 5e+244) tmp = 1.0 / cos((t_0 * (x * t_0))); else tmp = 1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[Sqrt[N[(0.5 / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], 5e+244], N[(1.0 / N[Cos[N[(t$95$0 * N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
x = |x|\\
y = |y|\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{0.5}{y}}\\
\mathbf{if}\;\frac{x}{y \cdot 2} \leq 5 \cdot 10^{+244}:\\
\;\;\;\;\frac{1}{\cos \left(t_0 \cdot \left(x \cdot t_0\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 x (*.f64 y 2)) < 5.00000000000000022e244Initial program 51.3%
add-log-exp51.3%
*-un-lft-identity51.3%
log-prod51.3%
metadata-eval51.3%
add-log-exp51.3%
div-inv50.8%
tan-quot50.8%
associate-*l/50.8%
pow150.8%
inv-pow50.8%
pow-prod-up65.4%
metadata-eval65.4%
metadata-eval65.4%
div-inv65.4%
*-commutative65.4%
associate-/r*65.4%
metadata-eval65.4%
Applied egg-rr65.4%
expm1-log1p-u63.7%
Applied egg-rr63.7%
expm1-log1p-u65.4%
add-sqr-sqrt30.2%
associate-*r*30.2%
Applied egg-rr30.2%
if 5.00000000000000022e244 < (/.f64 x (*.f64 y 2)) Initial program 2.5%
Taylor expanded in x around 0 12.8%
Final simplification28.7%
NOTE: x should be positive before calling this function
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (* y 2.0))))
(if (<= (/ (tan t_0) (sin t_0)) 1.17)
(/ 1.0 (cos (/ (cbrt -0.125) (/ y x))))
1.0)))x = abs(x);
y = abs(y);
double code(double x, double y) {
double t_0 = x / (y * 2.0);
double tmp;
if ((tan(t_0) / sin(t_0)) <= 1.17) {
tmp = 1.0 / cos((cbrt(-0.125) / (y / x)));
} else {
tmp = 1.0;
}
return tmp;
}
x = Math.abs(x);
y = Math.abs(y);
public static double code(double x, double y) {
double t_0 = x / (y * 2.0);
double tmp;
if ((Math.tan(t_0) / Math.sin(t_0)) <= 1.17) {
tmp = 1.0 / Math.cos((Math.cbrt(-0.125) / (y / x)));
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) y = abs(y) function code(x, y) t_0 = Float64(x / Float64(y * 2.0)) tmp = 0.0 if (Float64(tan(t_0) / sin(t_0)) <= 1.17) tmp = Float64(1.0 / cos(Float64(cbrt(-0.125) / Float64(y / x)))); else tmp = 1.0; end return tmp end
NOTE: x should be positive before calling this function
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Tan[t$95$0], $MachinePrecision] / N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 1.17], N[(1.0 / N[Cos[N[(N[Power[-0.125, 1/3], $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
x = |x|\\
y = |y|\\
\\
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\mathbf{if}\;\frac{\tan t_0}{\sin t_0} \leq 1.17:\\
\;\;\;\;\frac{1}{\cos \left(\frac{\sqrt[3]{-0.125}}{\frac{y}{x}}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (tan.f64 (/.f64 x (*.f64 y 2))) (sin.f64 (/.f64 x (*.f64 y 2)))) < 1.1699999999999999Initial program 70.4%
add-log-exp70.4%
*-un-lft-identity70.4%
log-prod70.4%
metadata-eval70.4%
add-log-exp70.4%
div-inv69.7%
tan-quot69.7%
associate-*l/69.7%
pow169.7%
inv-pow69.7%
pow-prod-up70.4%
metadata-eval70.4%
metadata-eval70.4%
div-inv70.7%
*-commutative70.7%
associate-/r*70.7%
metadata-eval70.7%
Applied egg-rr70.7%
add-cbrt-cube68.6%
pow368.5%
Applied egg-rr68.5%
Taylor expanded in x around -inf 71.3%
mul-1-neg71.3%
cos-neg71.3%
associate-/l*71.3%
Simplified71.3%
if 1.1699999999999999 < (/.f64 (tan.f64 (/.f64 x (*.f64 y 2))) (sin.f64 (/.f64 x (*.f64 y 2)))) Initial program 3.3%
Taylor expanded in x around 0 46.5%
Final simplification62.7%
NOTE: x should be positive before calling this function NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (/ x (* y 2.0)) 1e+185) (/ 1.0 (cos (exp (log (* x (/ 0.5 y)))))) 1.0))
x = abs(x);
y = abs(y);
double code(double x, double y) {
double tmp;
if ((x / (y * 2.0)) <= 1e+185) {
tmp = 1.0 / cos(exp(log((x * (0.5 / y)))));
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x / (y * 2.0d0)) <= 1d+185) then
tmp = 1.0d0 / cos(exp(log((x * (0.5d0 / y)))))
else
tmp = 1.0d0
end if
code = tmp
end function
x = Math.abs(x);
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if ((x / (y * 2.0)) <= 1e+185) {
tmp = 1.0 / Math.cos(Math.exp(Math.log((x * (0.5 / y)))));
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) y = abs(y) def code(x, y): tmp = 0 if (x / (y * 2.0)) <= 1e+185: tmp = 1.0 / math.cos(math.exp(math.log((x * (0.5 / y))))) else: tmp = 1.0 return tmp
x = abs(x) y = abs(y) function code(x, y) tmp = 0.0 if (Float64(x / Float64(y * 2.0)) <= 1e+185) tmp = Float64(1.0 / cos(exp(log(Float64(x * Float64(0.5 / y)))))); else tmp = 1.0; end return tmp end
x = abs(x) y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if ((x / (y * 2.0)) <= 1e+185) tmp = 1.0 / cos(exp(log((x * (0.5 / y))))); else tmp = 1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], 1e+185], N[(1.0 / N[Cos[N[Exp[N[Log[N[(x * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{y \cdot 2} \leq 10^{+185}:\\
\;\;\;\;\frac{1}{\cos \left(e^{\log \left(x \cdot \frac{0.5}{y}\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 x (*.f64 y 2)) < 9.9999999999999998e184Initial program 54.1%
add-log-exp54.1%
*-un-lft-identity54.1%
log-prod54.1%
metadata-eval54.1%
add-log-exp54.1%
div-inv53.6%
tan-quot53.6%
associate-*l/53.6%
pow153.6%
inv-pow53.6%
pow-prod-up69.2%
metadata-eval69.2%
metadata-eval69.2%
div-inv69.2%
*-commutative69.2%
associate-/r*69.2%
metadata-eval69.2%
Applied egg-rr69.2%
add-exp-log37.7%
Applied egg-rr37.7%
if 9.9999999999999998e184 < (/.f64 x (*.f64 y 2)) Initial program 5.4%
Taylor expanded in x around 0 12.5%
Final simplification34.1%
NOTE: x should be positive before calling this function NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 1.0)
x = abs(x);
y = abs(y);
double code(double x, double y) {
return 1.0;
}
NOTE: x should be positive before calling this function
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
x = Math.abs(x);
y = Math.abs(y);
public static double code(double x, double y) {
return 1.0;
}
x = abs(x) y = abs(y) def code(x, y): return 1.0
x = abs(x) y = abs(y) function code(x, y) return 1.0 end
x = abs(x) y = abs(y) function tmp = code(x, y) tmp = 1.0; end
NOTE: x should be positive before calling this function NOTE: y should be positive before calling this function code[x_, y_] := 1.0
\begin{array}{l}
x = |x|\\
y = |y|\\
\\
1
\end{array}
Initial program 47.1%
Taylor expanded in x around 0 61.0%
Final simplification61.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (* y 2.0))) (t_1 (sin t_0)))
(if (< y -1.2303690911306994e+114)
1.0
(if (< y -9.102852406811914e-222)
(/ t_1 (* t_1 (log (exp (cos t_0)))))
1.0))))
double code(double x, double y) {
double t_0 = x / (y * 2.0);
double t_1 = sin(t_0);
double tmp;
if (y < -1.2303690911306994e+114) {
tmp = 1.0;
} else if (y < -9.102852406811914e-222) {
tmp = t_1 / (t_1 * log(exp(cos(t_0))));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x / (y * 2.0d0)
t_1 = sin(t_0)
if (y < (-1.2303690911306994d+114)) then
tmp = 1.0d0
else if (y < (-9.102852406811914d-222)) then
tmp = t_1 / (t_1 * log(exp(cos(t_0))))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y * 2.0);
double t_1 = Math.sin(t_0);
double tmp;
if (y < -1.2303690911306994e+114) {
tmp = 1.0;
} else if (y < -9.102852406811914e-222) {
tmp = t_1 / (t_1 * Math.log(Math.exp(Math.cos(t_0))));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = x / (y * 2.0) t_1 = math.sin(t_0) tmp = 0 if y < -1.2303690911306994e+114: tmp = 1.0 elif y < -9.102852406811914e-222: tmp = t_1 / (t_1 * math.log(math.exp(math.cos(t_0)))) else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y * 2.0)) t_1 = sin(t_0) tmp = 0.0 if (y < -1.2303690911306994e+114) tmp = 1.0; elseif (y < -9.102852406811914e-222) tmp = Float64(t_1 / Float64(t_1 * log(exp(cos(t_0))))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y * 2.0); t_1 = sin(t_0); tmp = 0.0; if (y < -1.2303690911306994e+114) tmp = 1.0; elseif (y < -9.102852406811914e-222) tmp = t_1 / (t_1 * log(exp(cos(t_0)))); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, If[Less[y, -1.2303690911306994e+114], 1.0, If[Less[y, -9.102852406811914e-222], N[(t$95$1 / N[(t$95$1 * N[Log[N[Exp[N[Cos[t$95$0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
t_1 := \sin t_0\\
\mathbf{if}\;y < -1.2303690911306994 \cdot 10^{+114}:\\
\;\;\;\;1\\
\mathbf{elif}\;y < -9.102852406811914 \cdot 10^{-222}:\\
\;\;\;\;\frac{t_1}{t_1 \cdot \log \left(e^{\cos t_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
herbie shell --seed 2023228
(FPCore (x y)
:name "Diagrams.TwoD.Layout.CirclePacking:approxRadius from diagrams-contrib-1.3.0.5"
:precision binary64
:herbie-target
(if (< y -1.2303690911306994e+114) 1.0 (if (< y -9.102852406811914e-222) (/ (sin (/ x (* y 2.0))) (* (sin (/ x (* y 2.0))) (log (exp (cos (/ x (* y 2.0))))))) 1.0))
(/ (tan (/ x (* y 2.0))) (sin (/ x (* y 2.0)))))