
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - 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 + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -910000000.0) (* x y) (if (<= x 1.2e-90) (- z) (if (<= x 1.65e+143) (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -910000000.0) {
tmp = x * y;
} else if (x <= 1.2e-90) {
tmp = -z;
} else if (x <= 1.65e+143) {
tmp = x * 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 (x <= (-910000000.0d0)) then
tmp = x * y
else if (x <= 1.2d-90) then
tmp = -z
else if (x <= 1.65d+143) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -910000000.0) {
tmp = x * y;
} else if (x <= 1.2e-90) {
tmp = -z;
} else if (x <= 1.65e+143) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -910000000.0: tmp = x * y elif x <= 1.2e-90: tmp = -z elif x <= 1.65e+143: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -910000000.0) tmp = Float64(x * y); elseif (x <= 1.2e-90) tmp = Float64(-z); elseif (x <= 1.65e+143) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -910000000.0) tmp = x * y; elseif (x <= 1.2e-90) tmp = -z; elseif (x <= 1.65e+143) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -910000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.2e-90], (-z), If[LessEqual[x, 1.65e+143], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -910000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-90}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{+143}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -9.1e8 or 1.2000000000000001e-90 < x < 1.65e143Initial program 98.1%
Taylor expanded in y around inf 64.5%
if -9.1e8 < x < 1.2000000000000001e-90Initial program 100.0%
Taylor expanded in x around 0 68.2%
mul-1-neg68.2%
Simplified68.2%
if 1.65e143 < x Initial program 88.9%
*-commutative88.9%
sub-neg88.9%
distribute-rgt-in88.9%
metadata-eval88.9%
neg-mul-188.9%
associate-+r+88.9%
unsub-neg88.9%
+-commutative88.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in x around inf 67.7%
*-commutative67.7%
Simplified67.7%
Final simplification66.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.75e-69) (not (<= y 1.45e-19))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.75e-69) || !(y <= 1.45e-19)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - 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 ((y <= (-1.75d-69)) .or. (.not. (y <= 1.45d-19))) then
tmp = x * (z + y)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.75e-69) || !(y <= 1.45e-19)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.75e-69) or not (y <= 1.45e-19): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.75e-69) || !(y <= 1.45e-19)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.75e-69) || ~((y <= 1.45e-19))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.75e-69], N[Not[LessEqual[y, 1.45e-19]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{-69} \lor \neg \left(y \leq 1.45 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if y < -1.7500000000000001e-69 or 1.45e-19 < y Initial program 95.2%
Taylor expanded in x around inf 88.1%
+-commutative88.1%
Simplified88.1%
if -1.7500000000000001e-69 < y < 1.45e-19Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 85.0%
*-commutative85.0%
Simplified85.0%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.35e-44) (not (<= x 1.6e-89))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e-44) || !(x <= 1.6e-89)) {
tmp = x * (z + y);
} else {
tmp = -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 ((x <= (-1.35d-44)) .or. (.not. (x <= 1.6d-89))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e-44) || !(x <= 1.6e-89)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.35e-44) or not (x <= 1.6e-89): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.35e-44) || !(x <= 1.6e-89)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.35e-44) || ~((x <= 1.6e-89))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.35e-44], N[Not[LessEqual[x, 1.6e-89]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-44} \lor \neg \left(x \leq 1.6 \cdot 10^{-89}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.35e-44 or 1.59999999999999999e-89 < x Initial program 95.7%
Taylor expanded in x around inf 94.0%
+-commutative94.0%
Simplified94.0%
if -1.35e-44 < x < 1.59999999999999999e-89Initial program 100.0%
Taylor expanded in x around 0 70.2%
mul-1-neg70.2%
Simplified70.2%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.8e-73) (not (<= y 7e-20))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e-73) || !(y <= 7e-20)) {
tmp = x * y;
} else {
tmp = -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 ((y <= (-6.8d-73)) .or. (.not. (y <= 7d-20))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e-73) || !(y <= 7e-20)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.8e-73) or not (y <= 7e-20): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.8e-73) || !(y <= 7e-20)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.8e-73) || ~((y <= 7e-20))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.8e-73], N[Not[LessEqual[y, 7e-20]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-73} \lor \neg \left(y \leq 7 \cdot 10^{-20}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -6.80000000000000042e-73 or 7.00000000000000007e-20 < y Initial program 95.2%
Taylor expanded in y around inf 71.6%
if -6.80000000000000042e-73 < y < 7.00000000000000007e-20Initial program 100.0%
Taylor expanded in x around 0 53.5%
mul-1-neg53.5%
Simplified53.5%
Final simplification63.9%
(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 Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 97.2%
Taylor expanded in x around 0 30.9%
mul-1-neg30.9%
Simplified30.9%
herbie shell --seed 2024100
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))