
(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 (+ 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 98.4%
*-commutative98.4%
distribute-rgt-out--98.4%
cancel-sign-sub-inv98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3.8e+150)
(* x z)
(if (<= x -2.5e-85)
(* x y)
(if (<= x 4.1e-53)
(- z)
(if (or (<= x 5.6e+72) (not (<= x 2.7e+133))) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e+150) {
tmp = x * z;
} else if (x <= -2.5e-85) {
tmp = x * y;
} else if (x <= 4.1e-53) {
tmp = -z;
} else if ((x <= 5.6e+72) || !(x <= 2.7e+133)) {
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 <= (-3.8d+150)) then
tmp = x * z
else if (x <= (-2.5d-85)) then
tmp = x * y
else if (x <= 4.1d-53) then
tmp = -z
else if ((x <= 5.6d+72) .or. (.not. (x <= 2.7d+133))) 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 <= -3.8e+150) {
tmp = x * z;
} else if (x <= -2.5e-85) {
tmp = x * y;
} else if (x <= 4.1e-53) {
tmp = -z;
} else if ((x <= 5.6e+72) || !(x <= 2.7e+133)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.8e+150: tmp = x * z elif x <= -2.5e-85: tmp = x * y elif x <= 4.1e-53: tmp = -z elif (x <= 5.6e+72) or not (x <= 2.7e+133): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.8e+150) tmp = Float64(x * z); elseif (x <= -2.5e-85) tmp = Float64(x * y); elseif (x <= 4.1e-53) tmp = Float64(-z); elseif ((x <= 5.6e+72) || !(x <= 2.7e+133)) 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 <= -3.8e+150) tmp = x * z; elseif (x <= -2.5e-85) tmp = x * y; elseif (x <= 4.1e-53) tmp = -z; elseif ((x <= 5.6e+72) || ~((x <= 2.7e+133))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.8e+150], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.5e-85], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.1e-53], (-z), If[Or[LessEqual[x, 5.6e+72], N[Not[LessEqual[x, 2.7e+133]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+150}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.5 \cdot 10^{-85}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-53}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{+72} \lor \neg \left(x \leq 2.7 \cdot 10^{+133}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.79999999999999989e150 or 5.5999999999999998e72 < x < 2.7000000000000002e133Initial program 98.2%
Taylor expanded in y around 0 75.2%
Taylor expanded in x around inf 75.2%
*-commutative75.2%
Simplified75.2%
if -3.79999999999999989e150 < x < -2.5000000000000001e-85 or 4.1000000000000001e-53 < x < 5.5999999999999998e72 or 2.7000000000000002e133 < x Initial program 97.1%
Taylor expanded in y around inf 63.5%
if -2.5000000000000001e-85 < x < 4.1000000000000001e-53Initial program 100.0%
Taylor expanded in x around 0 74.8%
mul-1-neg74.8%
Simplified74.8%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -5e-85) (not (<= x 3.7e-53))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e-85) || !(x <= 3.7e-53)) {
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 <= (-5d-85)) .or. (.not. (x <= 3.7d-53))) 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 <= -5e-85) || !(x <= 3.7e-53)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e-85) or not (x <= 3.7e-53): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e-85) || !(x <= 3.7e-53)) 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 <= -5e-85) || ~((x <= 3.7e-53))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e-85], N[Not[LessEqual[x, 3.7e-53]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-85} \lor \neg \left(x \leq 3.7 \cdot 10^{-53}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.0000000000000002e-85 or 3.69999999999999982e-53 < x Initial program 97.5%
Taylor expanded in x around inf 94.3%
+-commutative94.3%
Simplified94.3%
if -5.0000000000000002e-85 < x < 3.69999999999999982e-53Initial program 100.0%
Taylor expanded in x around 0 74.8%
mul-1-neg74.8%
Simplified74.8%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.25e-84) (not (<= x 9.8e-60))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.25e-84) || !(x <= 9.8e-60)) {
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 ((x <= (-2.25d-84)) .or. (.not. (x <= 9.8d-60))) 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 ((x <= -2.25e-84) || !(x <= 9.8e-60)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.25e-84) or not (x <= 9.8e-60): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.25e-84) || !(x <= 9.8e-60)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.25e-84) || ~((x <= 9.8e-60))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.25e-84], N[Not[LessEqual[x, 9.8e-60]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{-84} \lor \neg \left(x \leq 9.8 \cdot 10^{-60}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.25000000000000008e-84 or 9.79999999999999977e-60 < x Initial program 97.5%
Taylor expanded in y around inf 53.2%
if -2.25000000000000008e-84 < x < 9.79999999999999977e-60Initial program 100.0%
Taylor expanded in x around 0 74.8%
mul-1-neg74.8%
Simplified74.8%
Final simplification61.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 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.4%
Taylor expanded in x around 0 32.5%
mul-1-neg32.5%
Simplified32.5%
Final simplification32.5%
herbie shell --seed 2024029
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))