
(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}
\\
\left(x + \sin y\right) + 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x + sin(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 * cos(y)) + (x + sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x + Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x + math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x + sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x + sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + \left(x + \sin y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.75) (not (<= x 5800000000.0))) (+ x z) (+ (sin y) (* z (cos y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.75) || !(x <= 5800000000.0)) {
tmp = x + z;
} else {
tmp = sin(y) + (z * cos(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 ((x <= (-0.75d0)) .or. (.not. (x <= 5800000000.0d0))) then
tmp = x + z
else
tmp = sin(y) + (z * cos(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.75) || !(x <= 5800000000.0)) {
tmp = x + z;
} else {
tmp = Math.sin(y) + (z * Math.cos(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.75) or not (x <= 5800000000.0): tmp = x + z else: tmp = math.sin(y) + (z * math.cos(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.75) || !(x <= 5800000000.0)) tmp = Float64(x + z); else tmp = Float64(sin(y) + Float64(z * cos(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.75) || ~((x <= 5800000000.0))) tmp = x + z; else tmp = sin(y) + (z * cos(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.75], N[Not[LessEqual[x, 5800000000.0]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.75 \lor \neg \left(x \leq 5800000000\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;\sin y + z \cdot \cos y\\
\end{array}
\end{array}
if x < -0.75 or 5.8e9 < x Initial program 100.0%
Taylor expanded in y around 0 92.2%
+-commutative92.2%
Simplified92.2%
if -0.75 < x < 5.8e9Initial program 99.9%
Taylor expanded in x around 0 92.5%
Final simplification92.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -3e+171)
t_0
(if (<= z -2.1e-10)
(+ x z)
(if (<= z 5.1e-58) (+ x (sin y)) (if (<= z 1e+219) (+ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -3e+171) {
tmp = t_0;
} else if (z <= -2.1e-10) {
tmp = x + z;
} else if (z <= 5.1e-58) {
tmp = x + sin(y);
} else if (z <= 1e+219) {
tmp = x + z;
} 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) :: tmp
t_0 = z * cos(y)
if (z <= (-3d+171)) then
tmp = t_0
else if (z <= (-2.1d-10)) then
tmp = x + z
else if (z <= 5.1d-58) then
tmp = x + sin(y)
else if (z <= 1d+219) then
tmp = x + z
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 tmp;
if (z <= -3e+171) {
tmp = t_0;
} else if (z <= -2.1e-10) {
tmp = x + z;
} else if (z <= 5.1e-58) {
tmp = x + Math.sin(y);
} else if (z <= 1e+219) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -3e+171: tmp = t_0 elif z <= -2.1e-10: tmp = x + z elif z <= 5.1e-58: tmp = x + math.sin(y) elif z <= 1e+219: tmp = x + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -3e+171) tmp = t_0; elseif (z <= -2.1e-10) tmp = Float64(x + z); elseif (z <= 5.1e-58) tmp = Float64(x + sin(y)); elseif (z <= 1e+219) tmp = Float64(x + z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -3e+171) tmp = t_0; elseif (z <= -2.1e-10) tmp = x + z; elseif (z <= 5.1e-58) tmp = x + sin(y); elseif (z <= 1e+219) tmp = x + z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3e+171], t$95$0, If[LessEqual[z, -2.1e-10], N[(x + z), $MachinePrecision], If[LessEqual[z, 5.1e-58], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1e+219], N[(x + z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -3 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{-10}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 5.1 \cdot 10^{-58}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 10^{+219}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.0000000000000001e171 or 9.99999999999999965e218 < z Initial program 99.9%
Taylor expanded in z around inf 98.3%
if -3.0000000000000001e171 < z < -2.1e-10 or 5.1e-58 < z < 9.99999999999999965e218Initial program 99.9%
Taylor expanded in y around 0 82.0%
+-commutative82.0%
Simplified82.0%
if -2.1e-10 < z < 5.1e-58Initial program 100.0%
Taylor expanded in z around 0 91.7%
+-commutative91.7%
Simplified91.7%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e+171) (not (<= z 6e+221))) (* z (cos y)) (+ x z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+171) || !(z <= 6e+221)) {
tmp = z * cos(y);
} else {
tmp = x + 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.2d+171)) .or. (.not. (z <= 6d+221))) then
tmp = z * cos(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+171) || !(z <= 6e+221)) {
tmp = z * Math.cos(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e+171) or not (z <= 6e+221): tmp = z * math.cos(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e+171) || !(z <= 6e+221)) tmp = Float64(z * cos(y)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e+171) || ~((z <= 6e+221))) tmp = z * cos(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e+171], N[Not[LessEqual[z, 6e+221]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+171} \lor \neg \left(z \leq 6 \cdot 10^{+221}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -3.20000000000000011e171 or 6.0000000000000003e221 < z Initial program 99.9%
Taylor expanded in z around inf 98.3%
if -3.20000000000000011e171 < z < 6.0000000000000003e221Initial program 100.0%
Taylor expanded in y around 0 75.7%
+-commutative75.7%
Simplified75.7%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (<= x -5e-24) x (if (<= x 4200000.0) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -5e-24) {
tmp = x;
} else if (x <= 4200000.0) {
tmp = z;
} else {
tmp = 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 (x <= (-5d-24)) then
tmp = x
else if (x <= 4200000.0d0) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5e-24) {
tmp = x;
} else if (x <= 4200000.0) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5e-24: tmp = x elif x <= 4200000.0: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5e-24) tmp = x; elseif (x <= 4200000.0) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5e-24) tmp = x; elseif (x <= 4200000.0) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5e-24], x, If[LessEqual[x, 4200000.0], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 4200000:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -4.9999999999999998e-24 or 4.2e6 < x Initial program 100.0%
Taylor expanded in x around inf 74.8%
if -4.9999999999999998e-24 < x < 4.2e6Initial program 99.9%
Taylor expanded in z around inf 68.4%
Taylor expanded in y around 0 48.6%
Final simplification62.6%
(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}
\\
x + z
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 72.5%
+-commutative72.5%
Simplified72.5%
Final simplification72.5%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 43.6%
Final simplification43.6%
herbie shell --seed 2024027
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))