
(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 5 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 (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
associate-+r+98.8%
metadata-eval98.8%
mul-1-neg98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e+64) (and (not (<= x 8.6e+89)) (<= x 7.5e+117))) (* x z) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e+64) || (!(x <= 8.6e+89) && (x <= 7.5e+117))) {
tmp = x * z;
} else {
tmp = (x * 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 ((x <= (-5.6d+64)) .or. (.not. (x <= 8.6d+89)) .and. (x <= 7.5d+117)) then
tmp = x * z
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e+64) || (!(x <= 8.6e+89) && (x <= 7.5e+117))) {
tmp = x * z;
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e+64) or (not (x <= 8.6e+89) and (x <= 7.5e+117)): tmp = x * z else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e+64) || (!(x <= 8.6e+89) && (x <= 7.5e+117))) tmp = Float64(x * z); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.6e+64) || (~((x <= 8.6e+89)) && (x <= 7.5e+117))) tmp = x * z; else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e+64], And[N[Not[LessEqual[x, 8.6e+89]], $MachinePrecision], LessEqual[x, 7.5e+117]]], N[(x * z), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{+64} \lor \neg \left(x \leq 8.6 \cdot 10^{+89}\right) \land x \leq 7.5 \cdot 10^{+117}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -5.60000000000000047e64 or 8.6000000000000003e89 < x < 7.5e117Initial program 98.2%
*-commutative98.2%
sub-neg98.2%
distribute-rgt-in98.2%
associate-+r+98.2%
metadata-eval98.2%
mul-1-neg98.2%
unsub-neg98.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 66.4%
Taylor expanded in x around inf 66.4%
if -5.60000000000000047e64 < x < 8.6000000000000003e89 or 7.5e117 < x Initial program 99.0%
*-commutative99.0%
sub-neg99.0%
distribute-rgt-in99.0%
associate-+r+99.0%
metadata-eval99.0%
mul-1-neg99.0%
unsub-neg99.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 88.3%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-124) (not (<= y 4.5e+26))) (- (* x y) z) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-124) || !(y <= 4.5e+26)) {
tmp = (x * y) - z;
} 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.5d-124)) .or. (.not. (y <= 4.5d+26))) then
tmp = (x * y) - z
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.5e-124) || !(y <= 4.5e+26)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-124) or not (y <= 4.5e+26): tmp = (x * y) - z else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-124) || !(y <= 4.5e+26)) tmp = Float64(Float64(x * y) - z); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.5e-124) || ~((y <= 4.5e+26))) tmp = (x * y) - z; else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-124], N[Not[LessEqual[y, 4.5e+26]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-124} \lor \neg \left(y \leq 4.5 \cdot 10^{+26}\right):\\
\;\;\;\;x \cdot y - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if y < -1.5e-124 or 4.49999999999999978e26 < y Initial program 98.5%
*-commutative98.5%
sub-neg98.5%
distribute-rgt-in98.5%
associate-+r+98.5%
metadata-eval98.5%
mul-1-neg98.5%
unsub-neg98.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 91.7%
if -1.5e-124 < y < 4.49999999999999978e26Initial program 99.1%
*-commutative99.1%
sub-neg99.1%
distribute-rgt-in99.2%
associate-+r+99.2%
metadata-eval99.2%
mul-1-neg99.2%
unsub-neg99.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 91.2%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.0) (* x z) (if (<= x 58.0) (- z) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= 58.0) {
tmp = -z;
} 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 <= (-1.0d0)) then
tmp = x * z
else if (x <= 58.0d0) then
tmp = -z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= 58.0) {
tmp = -z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = x * z elif x <= 58.0: tmp = -z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * z); elseif (x <= 58.0) tmp = Float64(-z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = x * z; elseif (x <= 58.0) tmp = -z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 58.0], (-z), N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 58:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1 or 58 < x Initial program 97.4%
*-commutative97.4%
sub-neg97.4%
distribute-rgt-in97.4%
associate-+r+97.4%
metadata-eval97.4%
mul-1-neg97.4%
unsub-neg97.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 51.9%
Taylor expanded in x around inf 51.9%
if -1 < x < 58Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 76.6%
Taylor expanded in x around 0 75.4%
neg-mul-175.4%
Simplified75.4%
Final simplification64.7%
(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 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
associate-+r+98.8%
metadata-eval98.8%
mul-1-neg98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 65.3%
Taylor expanded in x around 0 42.4%
neg-mul-142.4%
Simplified42.4%
Final simplification42.4%
herbie shell --seed 2023181
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))