
(FPCore (x y) :precision binary64 :pre TRUE (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)
use fmin_fmax_functions
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]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET t_0 = (x / (y * (2))) IN (tan(t_0)) / (sin(t_0)) END code
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\frac{\tan t\_0}{\sin t\_0}
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (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)
use fmin_fmax_functions
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]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET t_0 = (x / (y * (2))) IN (tan(t_0)) / (sin(t_0)) END code
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\frac{\tan t\_0}{\sin t\_0}
\end{array}
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (fabs x) (* (fabs y) 2.0)) 2e+32) (/ 1.0 (cos (* (fabs x) (/ 0.5 (fabs y))))) 1.0))
double code(double x, double y) {
double tmp;
if ((fabs(x) / (fabs(y) * 2.0)) <= 2e+32) {
tmp = 1.0 / cos((fabs(x) * (0.5 / fabs(y))));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((abs(x) / (abs(y) * 2.0d0)) <= 2d+32) then
tmp = 1.0d0 / cos((abs(x) * (0.5d0 / abs(y))))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs(x) / (Math.abs(y) * 2.0)) <= 2e+32) {
tmp = 1.0 / Math.cos((Math.abs(x) * (0.5 / Math.abs(y))));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs(x) / (math.fabs(y) * 2.0)) <= 2e+32: tmp = 1.0 / math.cos((math.fabs(x) * (0.5 / math.fabs(y)))) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(x) / Float64(abs(y) * 2.0)) <= 2e+32) tmp = Float64(1.0 / cos(Float64(abs(x) * Float64(0.5 / abs(y))))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs(x) / (abs(y) * 2.0)) <= 2e+32) tmp = 1.0 / cos((abs(x) * (0.5 / abs(y)))); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[x], $MachinePrecision] / N[(N[Abs[y], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], 2e+32], N[(1.0 / N[Cos[N[(N[Abs[x], $MachinePrecision] * N[(0.5 / N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((abs(x)) / ((abs(y)) * (2))) <= (200000000000000010732324408786944)) THEN ((1) / (cos(((abs(x)) * ((5e-1) / (abs(y))))))) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{\left|x\right|}{\left|y\right| \cdot 2} \leq 2 \cdot 10^{+32}:\\
\;\;\;\;\frac{1}{\cos \left(\left|x\right| \cdot \frac{0.5}{\left|y\right|}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 x (*.f64 y #s(literal 2 binary64))) < 2.0000000000000001e32Initial program 44.0%
Applied rewrites54.7%
Applied rewrites54.8%
if 2.0000000000000001e32 < (/.f64 x (*.f64 y #s(literal 2 binary64))) Initial program 44.0%
Taylor expanded in x around 0
Applied rewrites54.8%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (fabs x) (* (fabs y) 2.0)) 1e+31) (/ 1.0 (cos (/ (fabs x) (+ (fabs y) (fabs y))))) 1.0))
double code(double x, double y) {
double tmp;
if ((fabs(x) / (fabs(y) * 2.0)) <= 1e+31) {
tmp = 1.0 / cos((fabs(x) / (fabs(y) + fabs(y))));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((abs(x) / (abs(y) * 2.0d0)) <= 1d+31) then
tmp = 1.0d0 / cos((abs(x) / (abs(y) + abs(y))))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs(x) / (Math.abs(y) * 2.0)) <= 1e+31) {
tmp = 1.0 / Math.cos((Math.abs(x) / (Math.abs(y) + Math.abs(y))));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs(x) / (math.fabs(y) * 2.0)) <= 1e+31: tmp = 1.0 / math.cos((math.fabs(x) / (math.fabs(y) + math.fabs(y)))) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(x) / Float64(abs(y) * 2.0)) <= 1e+31) tmp = Float64(1.0 / cos(Float64(abs(x) / Float64(abs(y) + abs(y))))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs(x) / (abs(y) * 2.0)) <= 1e+31) tmp = 1.0 / cos((abs(x) / (abs(y) + abs(y)))); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[x], $MachinePrecision] / N[(N[Abs[y], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], 1e+31], N[(1.0 / N[Cos[N[(N[Abs[x], $MachinePrecision] / N[(N[Abs[y], $MachinePrecision] + N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((abs(x)) / ((abs(y)) * (2))) <= (9999999999999999635896294965248)) THEN ((1) / (cos(((abs(x)) / ((abs(y)) + (abs(y))))))) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{\left|x\right|}{\left|y\right| \cdot 2} \leq 10^{+31}:\\
\;\;\;\;\frac{1}{\cos \left(\frac{\left|x\right|}{\left|y\right| + \left|y\right|}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 x (*.f64 y #s(literal 2 binary64))) < 9.9999999999999996e30Initial program 44.0%
Applied rewrites54.7%
if 9.9999999999999996e30 < (/.f64 x (*.f64 y #s(literal 2 binary64))) Initial program 44.0%
Taylor expanded in x around 0
Applied rewrites54.8%
(FPCore (x y) :precision binary64 :pre TRUE (/ 1.0 (sin (* 0.5 (- PI (/ 1.0 (/ (fabs y) (fabs x))))))))
double code(double x, double y) {
return 1.0 / sin((0.5 * (((double) M_PI) - (1.0 / (fabs(y) / fabs(x))))));
}
public static double code(double x, double y) {
return 1.0 / Math.sin((0.5 * (Math.PI - (1.0 / (Math.abs(y) / Math.abs(x))))));
}
def code(x, y): return 1.0 / math.sin((0.5 * (math.pi - (1.0 / (math.fabs(y) / math.fabs(x))))))
function code(x, y) return Float64(1.0 / sin(Float64(0.5 * Float64(pi - Float64(1.0 / Float64(abs(y) / abs(x))))))) end
function tmp = code(x, y) tmp = 1.0 / sin((0.5 * (pi - (1.0 / (abs(y) / abs(x)))))); end
code[x_, y_] := N[(1.0 / N[Sin[N[(0.5 * N[(Pi - N[(1.0 / N[(N[Abs[y], $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (1) / (sin(((5e-1) * ((4 * atan(1)) - ((1) / ((abs(y)) / (abs(x)))))))) END code
\frac{1}{\sin \left(0.5 \cdot \left(\pi - \frac{1}{\frac{\left|y\right|}{\left|x\right|}}\right)\right)}
Initial program 44.0%
Applied rewrites54.7%
Applied rewrites54.7%
Applied rewrites54.7%
(FPCore (x y) :precision binary64 :pre TRUE (/ 1.0 (sin (* 0.5 (- PI (/ (fabs x) (fabs y)))))))
double code(double x, double y) {
return 1.0 / sin((0.5 * (((double) M_PI) - (fabs(x) / fabs(y)))));
}
public static double code(double x, double y) {
return 1.0 / Math.sin((0.5 * (Math.PI - (Math.abs(x) / Math.abs(y)))));
}
def code(x, y): return 1.0 / math.sin((0.5 * (math.pi - (math.fabs(x) / math.fabs(y)))))
function code(x, y) return Float64(1.0 / sin(Float64(0.5 * Float64(pi - Float64(abs(x) / abs(y)))))) end
function tmp = code(x, y) tmp = 1.0 / sin((0.5 * (pi - (abs(x) / abs(y))))); end
code[x_, y_] := N[(1.0 / N[Sin[N[(0.5 * N[(Pi - N[(N[Abs[x], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (1) / (sin(((5e-1) * ((4 * atan(1)) - ((abs(x)) / (abs(y))))))) END code
\frac{1}{\sin \left(0.5 \cdot \left(\pi - \frac{\left|x\right|}{\left|y\right|}\right)\right)}
Initial program 44.0%
Applied rewrites54.7%
Applied rewrites54.7%
(FPCore (x y) :precision binary64 :pre TRUE 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = 1 END code
1
Initial program 44.0%
Taylor expanded in x around 0
Applied rewrites54.8%
herbie shell --seed 2026092
(FPCore (x y)
:name "Diagrams.TwoD.Layout.CirclePacking:approxRadius from diagrams-contrib-1.3.0.5"
:precision binary64
(/ (tan (/ x (* y 2.0))) (sin (/ x (* y 2.0)))))