
(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 8 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 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.6e-5) (not (<= x 1.15e+22))) (+ x z) (+ (sin y) (* z (cos y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e-5) || !(x <= 1.15e+22)) {
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 <= (-7.6d-5)) .or. (.not. (x <= 1.15d+22))) 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 <= -7.6e-5) || !(x <= 1.15e+22)) {
tmp = x + z;
} else {
tmp = Math.sin(y) + (z * Math.cos(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.6e-5) or not (x <= 1.15e+22): tmp = x + z else: tmp = math.sin(y) + (z * math.cos(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.6e-5) || !(x <= 1.15e+22)) 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 <= -7.6e-5) || ~((x <= 1.15e+22))) tmp = x + z; else tmp = sin(y) + (z * cos(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.6e-5], N[Not[LessEqual[x, 1.15e+22]], $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 -7.6 \cdot 10^{-5} \lor \neg \left(x \leq 1.15 \cdot 10^{+22}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;\sin y + z \cdot \cos y\\
\end{array}
\end{array}
if x < -7.6000000000000004e-5 or 1.1500000000000001e22 < x Initial program 100.0%
Taylor expanded in y around 0 88.9%
+-commutative88.9%
Simplified88.9%
if -7.6000000000000004e-5 < x < 1.1500000000000001e22Initial program 99.9%
Taylor expanded in x around 0 93.8%
Final simplification91.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= x -0.0142)
(+ x z)
(if (<= x 5.2e-296)
t_0
(if (<= x 1.55e-214) (+ z (+ x y)) (if (<= x 1.32e+22) t_0 (+ x z)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (x <= -0.0142) {
tmp = x + z;
} else if (x <= 5.2e-296) {
tmp = t_0;
} else if (x <= 1.55e-214) {
tmp = z + (x + y);
} else if (x <= 1.32e+22) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (x <= (-0.0142d0)) then
tmp = x + z
else if (x <= 5.2d-296) then
tmp = t_0
else if (x <= 1.55d-214) then
tmp = z + (x + y)
else if (x <= 1.32d+22) then
tmp = t_0
else
tmp = x + z
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 (x <= -0.0142) {
tmp = x + z;
} else if (x <= 5.2e-296) {
tmp = t_0;
} else if (x <= 1.55e-214) {
tmp = z + (x + y);
} else if (x <= 1.32e+22) {
tmp = t_0;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if x <= -0.0142: tmp = x + z elif x <= 5.2e-296: tmp = t_0 elif x <= 1.55e-214: tmp = z + (x + y) elif x <= 1.32e+22: tmp = t_0 else: tmp = x + z return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (x <= -0.0142) tmp = Float64(x + z); elseif (x <= 5.2e-296) tmp = t_0; elseif (x <= 1.55e-214) tmp = Float64(z + Float64(x + y)); elseif (x <= 1.32e+22) tmp = t_0; else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (x <= -0.0142) tmp = x + z; elseif (x <= 5.2e-296) tmp = t_0; elseif (x <= 1.55e-214) tmp = z + (x + y); elseif (x <= 1.32e+22) tmp = t_0; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0142], N[(x + z), $MachinePrecision], If[LessEqual[x, 5.2e-296], t$95$0, If[LessEqual[x, 1.55e-214], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.32e+22], t$95$0, N[(x + z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;x \leq -0.0142:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-296}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-214}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -0.014200000000000001 or 1.32e22 < x Initial program 100.0%
Taylor expanded in y around 0 88.9%
+-commutative88.9%
Simplified88.9%
if -0.014200000000000001 < x < 5.2000000000000001e-296 or 1.55000000000000002e-214 < x < 1.32e22Initial program 99.9%
Taylor expanded in z around inf 67.3%
if 5.2000000000000001e-296 < x < 1.55000000000000002e-214Initial program 99.9%
Taylor expanded in y around 0 79.5%
+-commutative79.5%
+-commutative79.5%
associate-+l+79.5%
Simplified79.5%
Final simplification79.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.45e+128)
t_0
(if (<= z -2.75e-40)
(+ x z)
(if (<= z 5.05e-64) (+ x (sin y)) (if (<= z 2.35e+197) (+ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.45e+128) {
tmp = t_0;
} else if (z <= -2.75e-40) {
tmp = x + z;
} else if (z <= 5.05e-64) {
tmp = x + sin(y);
} else if (z <= 2.35e+197) {
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 <= (-2.45d+128)) then
tmp = t_0
else if (z <= (-2.75d-40)) then
tmp = x + z
else if (z <= 5.05d-64) then
tmp = x + sin(y)
else if (z <= 2.35d+197) 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 <= -2.45e+128) {
tmp = t_0;
} else if (z <= -2.75e-40) {
tmp = x + z;
} else if (z <= 5.05e-64) {
tmp = x + Math.sin(y);
} else if (z <= 2.35e+197) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -2.45e+128: tmp = t_0 elif z <= -2.75e-40: tmp = x + z elif z <= 5.05e-64: tmp = x + math.sin(y) elif z <= 2.35e+197: 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 <= -2.45e+128) tmp = t_0; elseif (z <= -2.75e-40) tmp = Float64(x + z); elseif (z <= 5.05e-64) tmp = Float64(x + sin(y)); elseif (z <= 2.35e+197) 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 <= -2.45e+128) tmp = t_0; elseif (z <= -2.75e-40) tmp = x + z; elseif (z <= 5.05e-64) tmp = x + sin(y); elseif (z <= 2.35e+197) 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, -2.45e+128], t$95$0, If[LessEqual[z, -2.75e-40], N[(x + z), $MachinePrecision], If[LessEqual[z, 5.05e-64], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.35e+197], N[(x + z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.45 \cdot 10^{+128}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.75 \cdot 10^{-40}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 5.05 \cdot 10^{-64}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 2.35 \cdot 10^{+197}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.45000000000000009e128 or 2.35e197 < z Initial program 99.8%
Taylor expanded in z around inf 82.7%
if -2.45000000000000009e128 < z < -2.75000000000000001e-40 or 5.05000000000000009e-64 < z < 2.35e197Initial program 99.9%
Taylor expanded in y around 0 78.1%
+-commutative78.1%
Simplified78.1%
if -2.75000000000000001e-40 < z < 5.05000000000000009e-64Initial program 100.0%
Taylor expanded in z around 0 95.0%
+-commutative95.0%
Simplified95.0%
Final simplification86.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e+32) (not (<= y 7.5e+23))) (+ x z) (+ z (+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+32) || !(y <= 7.5e+23)) {
tmp = x + z;
} else {
tmp = z + (x + 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 <= (-4d+32)) .or. (.not. (y <= 7.5d+23))) then
tmp = x + z
else
tmp = z + (x + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+32) || !(y <= 7.5e+23)) {
tmp = x + z;
} else {
tmp = z + (x + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e+32) or not (y <= 7.5e+23): tmp = x + z else: tmp = z + (x + y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e+32) || !(y <= 7.5e+23)) tmp = Float64(x + z); else tmp = Float64(z + Float64(x + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4e+32) || ~((y <= 7.5e+23))) tmp = x + z; else tmp = z + (x + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e+32], N[Not[LessEqual[y, 7.5e+23]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+32} \lor \neg \left(y \leq 7.5 \cdot 10^{+23}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + y\right)\\
\end{array}
\end{array}
if y < -4.00000000000000021e32 or 7.49999999999999987e23 < y Initial program 99.9%
Taylor expanded in y around 0 49.5%
+-commutative49.5%
Simplified49.5%
if -4.00000000000000021e32 < y < 7.49999999999999987e23Initial program 100.0%
Taylor expanded in y around 0 93.3%
+-commutative93.3%
+-commutative93.3%
associate-+l+93.3%
Simplified93.3%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (<= x -0.000175) x (if (<= x 1.2e+22) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.000175) {
tmp = x;
} else if (x <= 1.2e+22) {
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 <= (-0.000175d0)) then
tmp = x
else if (x <= 1.2d+22) 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 <= -0.000175) {
tmp = x;
} else if (x <= 1.2e+22) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.000175: tmp = x elif x <= 1.2e+22: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.000175) tmp = x; elseif (x <= 1.2e+22) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.000175) tmp = x; elseif (x <= 1.2e+22) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.000175], x, If[LessEqual[x, 1.2e+22], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000175:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+22}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.74999999999999998e-4 or 1.2e22 < x Initial program 100.0%
Taylor expanded in x around inf 81.0%
if -1.74999999999999998e-4 < x < 1.2e22Initial program 99.9%
Taylor expanded in z around inf 65.4%
Taylor expanded in y around 0 41.7%
Final simplification61.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 99.9%
Taylor expanded in y around 0 68.6%
+-commutative68.6%
Simplified68.6%
Final simplification68.6%
(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 99.9%
Taylor expanded in x around inf 45.2%
Final simplification45.2%
herbie shell --seed 2024036
(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))))