
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* z (+ 1.0 (* x (/ (sin y) z))))))
(if (<= z -1.12e+110)
t_0
(if (<= z -1.55e-181)
t_1
(if (<= z 3.2e-227) (* x (sin y)) (if (<= z 2.5e+59) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = z * (1.0 + (x * (sin(y) / z)));
double tmp;
if (z <= -1.12e+110) {
tmp = t_0;
} else if (z <= -1.55e-181) {
tmp = t_1;
} else if (z <= 3.2e-227) {
tmp = x * sin(y);
} else if (z <= 2.5e+59) {
tmp = t_1;
} else {
tmp = 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 = z * cos(y)
t_1 = z * (1.0d0 + (x * (sin(y) / z)))
if (z <= (-1.12d+110)) then
tmp = t_0
else if (z <= (-1.55d-181)) then
tmp = t_1
else if (z <= 3.2d-227) then
tmp = x * sin(y)
else if (z <= 2.5d+59) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double t_1 = z * (1.0 + (x * (Math.sin(y) / z)));
double tmp;
if (z <= -1.12e+110) {
tmp = t_0;
} else if (z <= -1.55e-181) {
tmp = t_1;
} else if (z <= 3.2e-227) {
tmp = x * Math.sin(y);
} else if (z <= 2.5e+59) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = z * (1.0 + (x * (math.sin(y) / z))) tmp = 0 if z <= -1.12e+110: tmp = t_0 elif z <= -1.55e-181: tmp = t_1 elif z <= 3.2e-227: tmp = x * math.sin(y) elif z <= 2.5e+59: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))) tmp = 0.0 if (z <= -1.12e+110) tmp = t_0; elseif (z <= -1.55e-181) tmp = t_1; elseif (z <= 3.2e-227) tmp = Float64(x * sin(y)); elseif (z <= 2.5e+59) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = z * (1.0 + (x * (sin(y) / z))); tmp = 0.0; if (z <= -1.12e+110) tmp = t_0; elseif (z <= -1.55e-181) tmp = t_1; elseif (z <= 3.2e-227) tmp = x * sin(y); elseif (z <= 2.5e+59) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.12e+110], t$95$0, If[LessEqual[z, -1.55e-181], t$95$1, If[LessEqual[z, 3.2e-227], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.5e+59], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{if}\;z \leq -1.12 \cdot 10^{+110}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.55 \cdot 10^{-181}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{-227}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.1200000000000001e110 or 2.4999999999999999e59 < z Initial program 99.8%
Taylor expanded in x around 0 88.8%
if -1.1200000000000001e110 < z < -1.55000000000000011e-181 or 3.2000000000000001e-227 < z < 2.4999999999999999e59Initial program 99.7%
expm1-log1p-u99.7%
Applied egg-rr99.7%
Taylor expanded in z around inf 98.3%
associate-/l*98.1%
Simplified98.1%
Taylor expanded in y around 0 80.2%
if -1.55000000000000011e-181 < z < 3.2000000000000001e-227Initial program 99.8%
Taylor expanded in x around inf 93.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e+109) (not (<= z 1.7e+59))) (* z (cos y)) (+ z (* x (* z (/ (sin y) z))))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+109) || !(z <= 1.7e+59)) {
tmp = z * cos(y);
} else {
tmp = z + (x * (z * (sin(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 ((z <= (-3.8d+109)) .or. (.not. (z <= 1.7d+59))) then
tmp = z * cos(y)
else
tmp = z + (x * (z * (sin(y) / z)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+109) || !(z <= 1.7e+59)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * (z * (Math.sin(y) / z)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e+109) or not (z <= 1.7e+59): tmp = z * math.cos(y) else: tmp = z + (x * (z * (math.sin(y) / z))) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e+109) || !(z <= 1.7e+59)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * Float64(z * Float64(sin(y) / z)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e+109) || ~((z <= 1.7e+59))) tmp = z * cos(y); else tmp = z + (x * (z * (sin(y) / z))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e+109], N[Not[LessEqual[z, 1.7e+59]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * N[(z * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+109} \lor \neg \left(z \leq 1.7 \cdot 10^{+59}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \left(z \cdot \frac{\sin y}{z}\right)\\
\end{array}
\end{array}
if z < -3.80000000000000039e109 or 1.70000000000000003e59 < z Initial program 99.8%
Taylor expanded in x around 0 88.8%
if -3.80000000000000039e109 < z < 1.70000000000000003e59Initial program 99.8%
expm1-log1p-u99.7%
Applied egg-rr99.7%
Taylor expanded in z around inf 91.9%
associate-/l*91.8%
Simplified91.8%
distribute-rgt-in91.8%
*-commutative91.8%
associate-*l*99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 85.9%
Final simplification86.9%
(FPCore (x y z)
:precision binary64
(if (<= y -1.5e+90)
(* z (cos y))
(if (or (<= y -0.014) (not (<= y 50000000000.0)))
(* x (sin y))
(+ z (* y (+ x (* y (* x (* y -0.16666666666666666)))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e+90) {
tmp = z * cos(y);
} else if ((y <= -0.014) || !(y <= 50000000000.0)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666)))));
}
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.5d+90)) then
tmp = z * cos(y)
else if ((y <= (-0.014d0)) .or. (.not. (y <= 50000000000.0d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * (x * (y * (-0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e+90) {
tmp = z * Math.cos(y);
} else if ((y <= -0.014) || !(y <= 50000000000.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666)))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.5e+90: tmp = z * math.cos(y) elif (y <= -0.014) or not (y <= 50000000000.0): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666))))) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.5e+90) tmp = Float64(z * cos(y)); elseif ((y <= -0.014) || !(y <= 50000000000.0)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(x * Float64(y * -0.16666666666666666)))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.5e+90) tmp = z * cos(y); elseif ((y <= -0.014) || ~((y <= 50000000000.0))) tmp = x * sin(y); else tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.5e+90], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -0.014], N[Not[LessEqual[y, 50000000000.0]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(x * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+90}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;y \leq -0.014 \lor \neg \left(y \leq 50000000000\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(x \cdot \left(y \cdot -0.16666666666666666\right)\right)\right)\\
\end{array}
\end{array}
if y < -1.49999999999999989e90Initial program 99.7%
Taylor expanded in x around 0 64.6%
if -1.49999999999999989e90 < y < -0.0140000000000000003 or 5e10 < y Initial program 99.5%
Taylor expanded in x around inf 60.5%
if -0.0140000000000000003 < y < 5e10Initial program 100.0%
Taylor expanded in y around 0 98.4%
Taylor expanded in z around 0 98.4%
*-commutative98.4%
associate-*r*98.4%
Simplified98.4%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.029) (not (<= y 50000000000.0))) (* x (sin y)) (+ z (* y (+ x (* y (* x (* y -0.16666666666666666))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.029) || !(y <= 50000000000.0)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666)))));
}
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.029d0)) .or. (.not. (y <= 50000000000.0d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * (x * (y * (-0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.029) || !(y <= 50000000000.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666)))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.029) or not (y <= 50000000000.0): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.029) || !(y <= 50000000000.0)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(x * Float64(y * -0.16666666666666666)))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.029) || ~((y <= 50000000000.0))) tmp = x * sin(y); else tmp = z + (y * (x + (y * (x * (y * -0.16666666666666666))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.029], N[Not[LessEqual[y, 50000000000.0]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(x * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.029 \lor \neg \left(y \leq 50000000000\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(x \cdot \left(y \cdot -0.16666666666666666\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.0290000000000000015 or 5e10 < y Initial program 99.6%
Taylor expanded in x around inf 52.5%
if -0.0290000000000000015 < y < 5e10Initial program 100.0%
Taylor expanded in y around 0 98.4%
Taylor expanded in z around 0 98.4%
*-commutative98.4%
associate-*r*98.4%
Simplified98.4%
Final simplification73.3%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 48.2%
+-commutative48.2%
Simplified48.2%
Final simplification48.2%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
expm1-log1p-u99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 36.9%
herbie shell --seed 2024146
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))